RobustToolbox icon indicating copy to clipboard operation
RobustToolbox copied to clipboard

Method for (almost) completely cloning an entity

Open LaCumbiaDelCoronavirus opened this issue 7 months ago • 1 comments

What am I kindly asking for as a feature request..?

EntityManager.CopyComponent() can reliably copy comps, when they don't reference any entities (i.e. don't contain EntityUids).

This can be used, along with some other methods such as RemoveComponent(), etc. to spawn an instance of that entity, and copy all the properties of it's components over to the cloned entity, to sometimes effectively clone it.

However, there's no good way to actually clone an entity that also contains more entities in components inside of itself. (and in some other really niche scenarios that I might not be mentioning)

Why? (and dungeons as an example)

Example: Dungeons

Dungeons work by spawning a dungeon atlas: a set of rooms to be used in the dungeon, from which they copy entity/decal/tile information to be used in spawning rooms without directly reading info from the map file of the dungeon.

The alternative to this approach, would of-course, be to read info from the dungeon's map file, which I'm very sure is not done because it would 1. maybe lead to lag, and 2. possibly be unreliable? (I'm mostly guessing, feel free to prove me wrong.)

As of writing, dungeons 'clone' entities from an atlas by spawning another instance of the entity that is being cloned. However, this presents a problem: any entity that was altered won't have the same alterations present in it's clone.

With dungeons as an example, what does that break?

Examples:

  1. Machine frames with custom boards inserted, will be spawned in their default state; they won't have any board in them.
  2. Anything with extra components added/removed, will be reset to their default state; they won't have any of the added components, and removed components will be re-added.

With dungeons as an example, What does this NOT affect?

Most things in storage containers, such as crates, will still spawn in those crates. I, however, have absolutely no idea what lets this happen, considering the fact that this isn't accounted for in any dungeon code that i've read.

The effects

(SS14, DungeonSystem.Rooms.cs, line ~173, is the code where the simple method of entity spawning should be replaced with entity cloning) Image

I would love to implement this myself.. if I had any clue of what I was doing.

Is this really a big issue?

Nah. Would be very nice to have though.

What do I know shouldn't be implemented with this?

Mobs. Really shouldn't clone mobs.

LaCumbiaDelCoronavirus avatar Apr 20 '25 18:04 LaCumbiaDelCoronavirus