Setting variables in Instantiated objects

Hey everyone!
I have a scene which instantiates some objects from a for loop. For example, three objects all by the name of foo(clone) in the hierarchy are instantiated. I would like to set a variable inside each object seperately, so for instance the variable ‘B’ could be ‘hey!’ in one, ‘hi!’ in the second and ‘hello!’ in the third; if possible it would be best if each object could be renamed, so instead of foo(clone), foo(clone) and foo(clone) it could be hey! hello! and hi!. Is there anyway of doing one of these methods via scripting?

As a second more minor question, is it possible to get the three instantiated objects to all be children of a single game object?

Thanks! :slight_smile:

Hello, yes it is possible to do both the renaming and setting the variables, what you want to do is change the gameObject.name and as for the variable you will have to get the component from the gameObject using gameObject.GetComponent() and then change the variable on the component.

If you want to have the gameObjects parented to another gameObject use the transform.parent

childGameObject.transform.parent = parentGameObject.transform;

Ah thats brill! Thanks veryyy much - its amazing how long you can spend searching for an answer that seems so simple! :stuck_out_tongue: