best practices for handling lists of GameObjects?

Hey guys,
I’m working on a project that relies heavily on run-time instantiated objects and prefabs. In many cases, some of these objects bring in instantiated children of their own. For these “parent” GameObjects, I’ve created a list that contains references to their children GameObjects.

Some of the variables of these GameObjects need to be referenced across the different objects.

Right now, I have a separate script that needs to be able call a function inside each of the children GameObjects.
To do this, I was thinking of having this script build a list to contain references to all these Gameobjects. It would find the Parent GameObjects, and go through each one’s list of children, adding the references to the new list.

*Except, I suspect this might not be the best way to approach things – Would it be best to modify the scripts that are generating my Parent and Child GameObjects, so that whenever one of them is created, the list is updated? So that the list is “managed” dynamically by each GameObject, rather that generated later by searching the scene?

Really, I’m hoping to understand which of these two approaches would be best. Please feel free to point out any other method that I haven’t considered.

I hope this makes sense.
Thanks,
-Juanelo

There is an alternative. Have a GameController where object “register” and “unregister”. This way the GameController keeps a singular list of objects and any object can ask for information about any other object. You can, by use of a Coroutine have the list validated every second as well.

Thanks, I think I will go that route.

What do you think the best way to handle registration would be? Should each object register itself on the GameController by default upon creation? I don’t quite see the need for the Coroutine; if each object is registering, it seems like it would be best to have it unregister on it’s own as well–

Do you think that would be effective? Is the Coroutine meant to be a safeguard in case objects are destroyed prior to unregistering or the references become obsolete?

Thanks,
-Juanelo