Is there a way to get entities by ID?

Hello,
I’m currently making a prototype using ECSY, and it appears to me that you can get the ID of an entity, but there isn’t a way to retrieve that entity using the ID (other than looping through entities and checking if they have that ID).
Am I correct about this?
My use case is for getting entities by location in a 2D grid. It seems to me that without modifying the current way of looking up entities, you would need to loop through all the entities with a Position component and check the position to do this, which must be much more expensive than having an array of entity IDs to directly get the entity by position. I’m also considering just storing references to the entities instead. Anyone have experience implementing position lookup in this kind of ECS?

Looking at others ECS’s -(I’ve been reading up on DOTS a lots to see how it handles things) it seems like you would normally maintain your own list of ids and then create a system that loops them and calls a “getEntityComponentData” method.

I wonder if there’s any advantage to having this kind of thing built into the query system though? A query that’s just a list of ids and gets cached along with the rest?

I suspect it maybe breaks the idea of such systems - maybe the component pooling?

I think maybe should use TagComponent to get the specific entity

2 Likes

Since in javascript everything is a reference type and entities store their components inside of them you can currently just take an array of entities and use that. You don’t need to get entities from their IDs if you just save the entities.

EDIT: After thinking on this, I do like not needing to keep track of IDs. That’s kind of the whole point of the querying system. Use TagComponents, when needed, like Bitfan suggested.

(old)
I do this by extending the World class. In my opinion, get methods for the EntityManager should be exposed in the World class. Please tell me if/why there is a better way.

What would using the TagComponent to fetch specific entities look like?

Here’s an example: say you create a “playerEntity” and you want systems to trigger when a player is created. Then, simply put a “playerTagComponent” on “playerEntity” and it will trigger those system queries that are looking for “playerTagComponent”.