- Edited
Hey all, got one I can't quite figure out. I've got a manager script that is holding all the references to resource nodes (rocks, trees, fish, etc) in my level scene. Every resource node has a specific ID associated with it, just an int. The game is networked, so its a client and server game. When the player clicks on a resource node it just sends the ID to the server.
Now here's the hard part: I need to fill an array or a dictionary with all the resource nodes on the server side. Originally I had an array which I could manually fill with all the resource nodes, but the problem was when passing the ID to the server it will take a while to search through every item in the array to find the one object that has the right ID. Instead I thought I could make a dictionary, that way I can just set the key to be the ID. Much easier to search for! But I'm not sure how to fill the dictionary.
The reason this is tricky is how far away the script is from the node objects. I've got the script attached to a node, World_1. Under that I have a child that is just called Nodes. And all the resource nodes are a child of that. Right now I can hard code it to say something like "for every child of World_1/Nodes/ create a dictionary entry for that child", but things will get difficult when I need to organize into more branches. I don't want to have to keep adding or removing from this coding every time I want to reorganize my hierarchy.
So is there a way to search through all the child nodes in a scene for a specific script? Or group? Or something that will be shared between all resource nodes? That way I can keep it flexible for when I expand later. Or do I just need to hard code all of the references?