Hi, I'm new to an ECS framework, I really like this simple, easy-to-use, and lightweight ECS framework, and I'm trying to use it in my game development. However, I've encountered a problem:
I need to create a large number of entities in one of my scenes and initialize them. It's common. For example, there are already 1,000 monsters on the map, and I need to create another 1,000 new monsters, each differing only in initial position and some attributes. However, the current API doesn't directly support this need.
The documentation provides two methods. One is the simple World.Spawn() method, which returns a specific Entity object. But the documentation also clearly states that this method is cost and only suitable for creating simple entities and. For creating entities with multiple components or for batch creation, the Spawner method is recommended. However, this method does not return the created objects. This confuses me.
I briefly looked into the source code of Spawner and found that it internally uses the Archetype's internal Spawn() method to create entities. This approach is quite different from directly using new Entity in World.Spawn(). I understand that this batch method does not directly create Entity objects, but rather creates their metadata, which still allows them to be queried in World.
Now I'm using a tricky way. I added a RowComponent to represent newly created but uninitialized entities. After using Spawner to create them, I query for all entities with RowComponent, initialize them one by one, and then remove the RowComponent.
I'm wondering if there's a more elegant way to get all these entities after creation so that I can initialize them. Alternatively, could the Spawner API be extended with a method that returns the created entities? After all, the Entity struct only needs its identity to be created.
Wish fennecs be better.
Hi, I'm new to an ECS framework, I really like this simple, easy-to-use, and lightweight ECS framework, and I'm trying to use it in my game development. However, I've encountered a problem:
I need to create a large number of entities in one of my scenes and initialize them. It's common. For example, there are already 1,000 monsters on the map, and I need to create another 1,000 new monsters, each differing only in initial position and some attributes. However, the current API doesn't directly support this need.
The documentation provides two methods. One is the simple
World.Spawn()method, which returns a specificEntityobject. But the documentation also clearly states that this method is cost and only suitable for creating simple entities and. For creating entities with multiple components or for batch creation, theSpawnermethod is recommended. However, this method does not return the created objects. This confuses me.I briefly looked into the source code of
Spawnerand found that it internally uses theArchetype's internalSpawn()method to create entities. This approach is quite different from directly usingnew EntityinWorld.Spawn(). I understand that this batch method does not directly createEntityobjects, but rather creates their metadata, which still allows them to be queried inWorld.Now I'm using a tricky way. I added a
RowComponentto represent newly created but uninitialized entities. After usingSpawnerto create them, I query for all entities withRowComponent, initialize them one by one, and then remove theRowComponent.I'm wondering if there's a more elegant way to get all these entities after creation so that I can initialize them. Alternatively, could the
SpawnerAPI be extended with a method that returns the created entities? After all, theEntitystruct only needs its identity to be created.Wish fennecs be better.