I am wondering if there is a better way than storing the entity ID. For the sake of example, let's assume I have a world with many entities who implement the component Name. Every x amount of time I want these entities to print "Hello, I am greeterName, have a nice day greetedName".
My current way to go would be to create a component BestFriend
, and to store in it the entity ID of the best friend entity. Then I would make a system GreetBestFriend
that query all of the entities with the Name
and BestFriend
components and loop through that query to find the entity that matches the BestFriend
's stored ID.
My concerns about this method are:
- Can I be sure that the referenced entity ID will not be changed at some point?
- Having to loop through all the instances of the query seems inefficient.
As mentioned, the above case is just for the sake of example. I am more generally interested in learning patterns that allow entities to reference each other.