Does Prefab conversion not work unless there is a field with an Entity type?

During the conversion process, it seems that I can’t store an Entity prefab (converted from a GameObject prefab) in anything except an Entity field on a runtime component.

In particular, I was creating a managed component (during conversion) with a Dictionary<int, Entity> and storing the converted Entity prefabs as values. However, at runtime the values ended up pointing to completely different Entities; although the actual Entity index & version didn’t change, it seemed that the Entity prefabs had been remapped to a different index & version.

Meanwhile, if I just store a converted Entity prefab in an Entity field on any runtime component, that field seems to update at runtime.

Is this the intended behavior? If there is something that updates converted Entity fields at runtime, under what conditions are they updated?

Indeed, the expected behavior is that Entity references in unmanaged IComponentData and IBufferElementData components are remapped automatically, while Entity references in ISharedComponentData and those stored in managed containers are not remapped.

During conversion, the entity fields in the supported components are serialized with the remapping information, which enable Unity to remap them when the scene data is loaded at runtime. This is not done on managed components, for performance reasons.

1 Like