- Home /
object pool - how to use it / best practice
hi..i have a question about tracking the objects in the scene. i have a lot of objects in the scene, i would like to know what is the best practice to track their state
here is the example of what structure i have in the scene:
Root
ObjectGroup1
ObjectSubGroup1
ObjectSubGroup2
ObjectGroup2
ObjectSubGroup1
ObjectSubGroup2
ObjectGroup3
ObjectSubGroup1
ObjectSubGroup2
every group and subgroup have meshes, colliders, etc... so far i was checking the state of the object and other things by getting the component that is attached to the script and reading the values. so every object have script attached to it, where i have values, for example transparent,hidden, value for alpha and other things...
is there a way to get the list of all objects and maintain their state in array. so every time i need to get the state or value that is specific for object i search for a name in the array and read its values?
can somebody point me in the right direction or provide examples, it would be appreciated.
thread at forums: http://forum.unity3d.com/threads/79266-object-pool
I mean, are they all being instantiated from the same prefab/GameObject? Are you looking for a way to query/change values on multiple scripts spread across many GameObjects? I'm just not sure what you're trying to do.
Answer by burnumd · Feb 23, 2011 at 08:42 PM
If I understand your question correctly, I'd probably differentiate them by GameObject name. You can change that as you create them in the Editor or when you instantiate them using Object.name, ie
//JS
var newObject = Instantiate (myObject);
newObject.name = newObject.name + " " + someUniqueId;
Then put them in a Dictionary
var myObjects : Dictionary.<string, GameObject> = Dictionary.<string, GameObject> ();
and when you instantiate them
var newObject = Instantiate (myObject);
newObject.name = newObject.name + " " + someUniqueId;
myObjects.Add (newObject.name, newObject);
Then you can access them by name with
myObjects[nameToCheck];
Your answer
Follow this Question
Related Questions
How to properly create a 2 dimensional array of an object. [C#] 1 Answer
How to remove objects from a list ? 3 Answers
A node in a childnode? 1 Answer
Convert Object[] to List 3 Answers
properly initializing my arrays (C#) 2 Answers