I have predator animals that keep track of prey animals. At first I kept them in an array but when one of the prey dies or is eaten I get an invalid element in the predator's prey array, which hints me this is not the way.
What is the best practices way of storing collections of other nodes to avoid having to clean up?
- children nodes
Prey nodes can't be children of predators since there are many types of predators which share prey.
- groups
That could work if I assign a group for each species, but that's a lot of groups. Is that the appropiate way?
pick_random from group each time the predator is instructed to hunt.
- signal on death/freed
Since I have to register each new prey to each potential predator at birth, I could also connect the free signal and delete from the array reactivelly.
- blackboard
have a blackboard object each animal registers to. I think this wouldn't be that different to the groups option.
any more ideas? how would you do it?