- Home /
[Solved] Renaming game object clones instantiated
I have a script that refers to myObject(Clone). The script however, includes destroying this object and instantiating a second time, third time, fourth time, etc. The name changes to myObject(Clone)(Clone) and keeps adding (Clone) as more are instantiated. How can I avoid this or change this name so that they are all the same. Only one is active at a time, so I'd prefer they all just be named "myObject"
Answer by Eric5h5 · Apr 11, 2012 at 06:33 PM
var prefab : GameObject;
function Start () {
var clone = Instantiate (prefab);
clone.name = "Whatever";
}
start() method calls as soon as we hit play button, Awake() gets called prior to Start().Rena$$anonymous$$g , initialisations are one time operations so its better to write it in start which gets called only once unless you reload scene or deactivate/activate object.Remember string operations are costly which collects GC so if possible do not do it or do it only once. Nsks
Why so many question marks???????????????
@Eric5h5 I would be extremely grateful if you could please take assist me with clone several game objects. I asked the original question was asked on Stackoverflow how to clone several game objects in a way that clone properties of one can be adjusted to match all others in scene view, which hasn't been answered.
Your answer
![](https://koobas.hobune.stream/wayback/20220613070211im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I refer to the name of the game object the script is attached to? 1 Answer
Fire an event when gameObject has been renamed? 2 Answers
Sharing components amongst different gameobjects 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
All subsequent instantiated objects = auto-named with suffix (Clone)? 1 Answer