Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
4
Question by Chesley · Dec 03, 2011 at 10:17 PM · instantiateprefabclonesimple

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?

Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FLASHDENMARK · Dec 03, 2011 at 10:21 PM 1
Share

$$anonymous$$ay I ask why?

avatar image WillTAtl · Dec 03, 2011 at 11:03 PM 1
Share

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.

avatar image FLASHDENMARK · Dec 04, 2011 at 01:05 PM 0
Share

I ask why, because I would like a reason for why he wants to change the names.

avatar image WillTAtl · Dec 04, 2011 at 03:55 PM 1
Share

Yes, thanks, I grasp the basic motivation behind questions in general; by the same token, Chelsey asked because they want to know how. :P

avatar image Chesley · Dec 05, 2011 at 07:37 PM 0
Share

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?

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

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";
Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Chesley · Dec 04, 2011 at 12:36 PM 0
Share

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

avatar image WillTAtl · Dec 04, 2011 at 03:56 PM 0
Share

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!

avatar image Bunny83 · Dec 04, 2011 at 08:32 PM 5
Share

Or just use this:

 var obj = Instantiate(myPrefab,pos,rot);
 obj.name = myPrefab.name;
avatar image WillTAtl · Dec 04, 2011 at 09:21 PM 2
Share

...

Today's award for seeing the obvious and simple solution everyone else missed is goes to Bunny83!

avatar image Tseng · Dec 05, 2011 at 03:02 AM 1
Share

You can of course put Bunny83 solution into a static public method, and call this ins$$anonymous$$d of the built-in Instantiate(...)

Show more comments
avatar image
4

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
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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. alt text


k3gifu6.png (435.6 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

destroy asset is not permitted to avoid data loss? 0 Answers

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges