Skip to content

Retreiving entities next to one entity #171

Answered by Doraku
mc-lep asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, the main reason I discourage from storing entities in your own container is because you would then be responsible to keep it up to date with the entities state (were they disposed? did their composition changed? ...) but if you know what you are doing it is completely valid to do so.
There is an existing container built in that could help you to achieve a spacial grid, the EntityMultiMap<>. I actually use just that in the boids sample. I use a GridId component that is recalculated when the entities move and when the multimap is notified of those changes it move entities around in what is basically a Dictionary<GridId, Entity[]> so I can access neighbors in O(1) (and as it is a native…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by mc-lep
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants