I’m trying to instantiate a bunch of 3d tiles that will build a grid/tile kind of map in the screen. It was previously being done successfully with objects, but now I’m refactoring that code to work with ECS.
Here’s what I’ve done:
- Created a subscene;
- Put a new game object inside that subscene, so it can be converted to Entity. That’s the only object currently in my subscene;
- Added a monobehaviour (which has a baker) to that object;
- In the Bake function, I filled up a NativeHashMap<int2, MyStructure> field in the authoring with a for loop. It looks something like this: “authoring.Nodes.Add(pos, new MyStruct { stuff… })”. One of the fields of this “MyStructure” thing is an Entity type that receives GetEntity() of the prefab that needs to be in that specific struct for instatiation later;
- Created a System to handle the instantiation itself using burstcompile. Removing burstcompile changes nothing though;
- Added [UpdateInGroup(typeof(InitializationSystemGroup))] to the system struct because I was getting an error while trying to get a singleton that had not yet been created while running the “OnUpdate logic” to get my “Nodes” array.
- Did a “for” loop (iterating through all the keys) to do the instantiation in the “OnUpdate” method of that system and that loop does this: "Entity x = ecb.Instantiate(map.Nodes[keys*].Entity);*". Then, after the for loop finishes I did: “ecb.Playback(state.EntityManager);”
Relevant Info (maybe): I have an AssetsManager that loads the resources by using “Resources.LoadAll<>()” and stores them in a dictionary in which the key is the asset name. This is done in its Awake method. On the “Bake” function I check if “AssetsManager.Instance” is not null so I can do the for loop described by the item 2 (above). The “Instance” is set before the “Resources.LoadAll<>()” call, and when setting my Entity I do exactly this: "Entity = GetEntity(AssetsManager.Instance.GetAsset(authoring.MapStructure.Tiles*.PrefabName).gameObject)*". I don’t think this is the cause of the problem, because the baker ends up adding the nodes when I get to the System part, so, I think the prefabs have been already loaded by then. After all, the System “for” loop runs through all my 168 nodes which are created by the baker.
Expected Result: In my tests, only one kind of prefab is being associated with all nodes because I wanted to keep things simple at first. So, for each node I expected to have its associated prefab (which in the test scenario is always the same) instantiated and visible on the screen as an entity in order to build the tile/grid/thing map. If that worked, I would create the real map associating different prefabs to each node as necessary.
Problem: For some reason when I run this thing I can see in the Entity Hierarchy (runtime) a blue instance of my prefab, complete with all components that it shoud have (I think) at the same level of the game object to which I added the monobehavior with baking. Together with that bunch of Unity internal Systems and Components that fill up the hierarchy at runtime by default, I also get one “Unity.Entities.EndFixedStepSimulationEntityCommandBufferSyste” (yes, without the “m”, not a typo) for each Entity I tried to instantiate, with various Indexes and Versions. Their components are simply “Tags”, with “Simulate” checked, “End Fixed Step Simulation Entity Command Buffer System | Singleton”, which is empty if I try to expand, and “System Instance”, which also is empty as I expand. No Aspects, and in Relationships I have a “End Fixed Step Simulation Entity Command Buffer System” >> “Query #1” >> “Unity.Entities.EndFixedStepSimulationEntityCommandBufferSystem.Singleton”. The “>>” in this case represents that one is nested to the one before it, so only one “root” element in the Relationships. Nothing is rendered, no other components are added, and there’s no clue that those things were created by my instatiations other than they go away if I comment away the instantiation code, and they seem to be as plenty as my instatiation for loop count (which is 168 in this test). The results are the same if using “state.EntityManager” instead of the “EntityCommandBuffer”.
I have a feeling this is a noob problem caused by my lack of knowledge about the ECS tools. Been messing around with ECS for just a couple of days on a project that’s been shelved for quite some time because it’s very CPU intensive and I didn’t manage to make it run proberly back then. Since ECS is now at pre release stages I thought I should give it a go, and I would be very grateful if anyone could offer me some help.
Thanks in advance.



