Hi all I am having an issue with upgrading a project to the latest unity entities packages. Unity 2020.1.0b4.3439.
This code used to run fine but now I’m getting an issue that I don’t fully understand why its not working.
I have a function in my game (RunGame) that I use to call numerous public static methods to initialise things across my game. I do this after the scene has loaded and this has worked fine previously. In my editor I have a gameobject that converts GameObjects to entities using the IDeclareReferencedPrefabs and IConvertGameObjectToEntity and these entities are stored in the “myType” IComponentData that I query in the code below. This gameobject is also converted to entity with “convert and destroy”.
Here is the gameobject->entity conversion:
[RequiresEntityConversion]
public class SpawnerProxy : MonoBehaviour, IDeclareReferencedPrefabs, IConvertGameObjectToEntity
{
public GameObject myGO;
public void DeclareReferencedPrefabs(List<GameObject> gameObjects)
{
gameObjects.Add(myGO);
}
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
var data = new myType
{
myEntity = conversionSystem.GetPrimaryEntity(myGO),
};
dstManager.AddComponentData(entity, data);
}
}
public struct myType : IComponentData
{
public Entity myEntity;
}
In the code below, I am trying to get component data from the “myType” query but for some reason this returns an empty object. I expect there to be 1 object in there which is how it used to work. Why does this no longer work?
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
public static void RunGame()
{
MySystem.InitialiseStuff();
}
public class MySystem : ComponentSystem
{
EntityQuery myQuery;
protected override void OnCreate()
{
myQuery = GetEntityQuery(typeof(myType));
}
public static InitialiseStuff()
{
var myTypeThings = myQuery.ToComponentDataArray<myType>(Allocator.TempJob);
/* ^^^^^ This thing is empty, it didnt used to be */
}
}