Say I have a bunch of worlds that might have some of the same archetypes in them. If i use one of the EntityManagers from one of the worlds to populate a static Archetype for use in other worlds would that cause any issues,or would that archetype somehow defined by the parameter of the world it was created from?
would ECSTestDataArchetype be usable in any/all worlds that have ECSTestData and ECSTestData2 or would I be required to define that archetype for each world?
I don’t actually know if it’ll work or not, but it seems like a bad idea even if it does because there’s no guarantee it’ll continue to work in future.
Archetype are created using an instance of ArchetypeManager local to EntityManage so as far as I can tell it’s not shared between worlds. From a glance I think the biggest issue might be SharedComponentData.
If you want to keep a static reference to share, why not just keep a ComponentType[ ] collection.
had not thought of that. I think that might work better.
maybe use those to search through all of the already created archetypes in the EnitityManagers Arch list.
So i decided to do a little refactoring and make some static ComponentType[ ] that i can use to reference and archetype in an EntityManager. A few things to note
Archetypes are created with an Entity ComponentType under the hood. So any checks in EntityArchetype.ComponentTypes should have that firts
ComponentType order in EntityArchetype.ComponentTypes is not guaranteed for some reason. Some ComponentType seem to swap positions under the hood. meaning no ComponentType[ ].Equals(ComponentType[ ]) easy checks
This was kind of frustrating at first and not really an “optimal” solution but given that the archetypes are retrieved only once on system creation its not too big of a deal for now.
So unless you’re creating a hell of a lot of entities that a little extra work sorting the types and doing a hash is going to cause an issue, I don’t expect just passing in a ComponentType array instead of an archetype will cause any issues*
This all said, I’m hugely against using static data like this.
you’d need to convert it to an Archetype to pass to a job or an entity command buffer.
Probably could have saved some time just looking at the code lol didnt realize you could get the same Archetype if it was already created. Sort of took the “Create” part too literally lol