Simple Prefab Instantiate "(Clone)" Question
Is it possible to remove the "(Clone)" thingy that Unity adds to the GameObject name when i spawn a prefab?
I don't know why Chelsey wants to do it either, but may I ask why you ask why? It's a very straightforward question.
I ask why, because I would like a reason for why he wants to change the names.
Yes, thanks, I grasp the basic motivation behind questions in general; by the same token, Chelsey asked because they want to know how. :P
If somebody reads this, it's just for name display, when you go over an object with my mouse that i see the name ins$$anonymous$$d of name + (Clone)
Now i ask you guys something, why is it weird that i want the (clone) to be deleted?
Answer by WillTAtl · Dec 03, 2011 at 11:06 PM
just set the name property of the object returned from Instantiate, like this...
var obj=Instantiate(myPrefab,pos,rot);
obj.name="NewName";
is it possible to do that with like: obj.name = name - "(Clone)"
because I'm working with SOO many prefabs that i need to get the name and change it ins$$anonymous$$d of just change it with a var which will take a long time since I'm working with so many of them
No, you can't string arithmetic only supports +, not -. See aldonaletto's answer for a general way of just automatically stripping the "(Clone)" from the end. There's not going to be a way to just set the setting in one place and have it happen automatically, though; you will have to add code to every place you call Instantiate!
Or just use this:
var obj = Instantiate(myPrefab,pos,rot);
obj.name = myPrefab.name;
...
Today's award for seeing the obvious and simple solution everyone else missed is goes to Bunny83!
You can of course put Bunny83 solution into a static public method, and call this ins$$anonymous$$d of the built-in Instantiate(...)
Answer by aldonaletto · Dec 04, 2011 at 02:09 PM
You can use some Unityscript string functions to eliminate the (Clone) string
var obj = Instantiate(objPrefab, position, rotation); // create the object... var pos = obj.name.IndexOf("("); // find the left parenthesis position... obj.name = obj.name.Substring(0, pos); // and get only the substring before it
Answer by nastajus · Apr 14, 2014 at 11:29 PM
Had the following problem with the substring renaming. Dunno why it but permanently changed my prefab name, in such a way that didn't make sense, and wouldn't let me rename. I had to delete all my instances and recreate so they'd remain connected to the prefab... Now I'm afraid to assign names... Using latest Unity.
Your answer
![](https://koobas.hobune.stream/wayback/20220613061743im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unable to set position of instantiated prefab 1 Answer
I need help destroying a clone on function. 1 Answer
Saving Instantiated objects,Saving Instantiated objects 0 Answers
Prefab Enemy2 to track all prefab Enemy1's Instantiates transforms: How? 1 Answer
destroy asset is not permitted to avoid data loss? 0 Answers