Hello, hope you’re all well!
I’ve encountered an issue where a prefab that is converted to an Entity no longer changes when I add/remove new authoring components.
I’ll elaborate;
I have a main scene and a sub-scene within it.
Within the sub-scene is a GameObject with a SpawnerAuthoring component attached.
The SpawnerAuthoring is basically the following (with some variables removed for brevity):
public class SpawnerAuthoring : MonoBehaviour, IConvertGameObjectToEntity, IDeclareReferencedPrefabs
{
[SerializeField]
private GameObject personPrefab;
public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)
{
referencedPrefabs.Add(personPrefab);
}
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
var prefabAsEntity = conversionSystem.GetPrimaryEntity(personPrefab);
dstManager.AddComponentData(entity, new Spawner
{
Prefab = prefabAsEntity
});
}
}
I then drag the prefab (which has a ConvertToEntity component attached) into the Authoring component instance. Up until now, any changes made to this prefab (like adding new components) was seen in both the Prefab Entity as well as those entities spawned based on that prefab.
Now though, if I add anything to this prefab, as well as remove anything, the Entity Prefab does not reflect this in the Entity Debugger. Any systems counting on a given component being on the spawned entities won’t pick the entities up as they do not have the component. I’m 100% certain it’s the correct prefab being referenced; clicking it in the Spawner GameObject’s inspector takes me straight to it.
I’ve tried closing and reopening Unity. The components are structs, and they do implement IComponentData
and just contain a float. Even tried with empty components (tags). Whether it has a manual authoring script or using the generate attribute, it has the same issue. I’ve tried re-assigning the prefab as well. Only thing I haven’t tried is deleting the prefab and creating it again.
Weirdly, this issue occurs when the sub-scene is closed for editing. If I open the sub-scene for editing, suddenly the prefab entity is correct and is as it should be when I click Play. I shouldn’t have to have the sub-scene open for it to work though, right?
Just wondering if anyone has experienced this before…I’m sure I’m just doing something wrong.
Any help greatly appreciated - thank you for reading this far!