Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed May 03, 2016 at 12:53 AM by Obumbrata for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Obumbrata · Aug 03, 2012 at 06:22 AM · prefabinstanceclonename

How to remove the (Clone) from instantiated prefab C#

I've tried to remove the the (Clone) by renaming the instantiated prefab but it stays! eg: Fighter0*(Clone)*

How can I remove it?

Thanks!

  public void Spawner()
  {
  ClassPick = 0; //(int)Random.Range(0,2.999f);
  
  Debug.Log("Setting Class");
 
  switch(ClassPick)
  {
  case 0 :
  enemy = Resources.Load("Fighter")  as GameObject;
  Instantiate(enemy, new Vector3(0,0,10),Quaternion.identity);
  enemy.name = "Fighter" + prefabIndex;
  ecounter++;
  
  break;
  }

 

}

Comment
Add comment · Show 1
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 Obumbrata · May 03, 2016 at 12:57 AM 0
Share

Thanks guys! Just got a message that this was answered.

2 Replies

  • Sort: 
avatar image
6
Best Answer

Answer by GibTreaty · Aug 03, 2012 at 06:44 AM

Use

GameObject go = Instantiate(enemy, new Vector3(0,0,10),Quaternion.identity) as GameObject;

go.name = go.name.Replace("(Clone)", "");

Comment
Add comment · Show 9 · 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 Radon · Aug 03, 2012 at 06:50 AM 0
Share

I believe that will change the name of the original prefab

avatar image GibTreaty · Aug 03, 2012 at 07:16 AM 0
Share

I didn't realize before that he was actually setting the prefab's name and not the instantiated object's name.

avatar image Artyom-Abgaryan · Jul 19, 2013 at 07:47 PM 0
Share

nice, thanks !

avatar image Bunny83 · Jul 19, 2013 at 08:30 PM 4
Share

It's easier this way:

     GameObject go = Instantiate(enemy /* ...*/ );
     go.name = enemy.name;
avatar image gegagome Bunny83 · May 01, 2016 at 06:28 PM 0
Share

This tip worked great!

Thanks

avatar image gillemp Bunny83 · Aug 07, 2019 at 10:17 PM 1
Share

Even easier (if you do not need to keep track of the prefab). Instantiate(prefab).name = prefab.name; This should instantiate the object and change its name to the one in the prefab.

avatar image Bunny83 gillemp · Aug 08, 2019 at 12:18 AM 0
Share

Well, it's not really easier. It's just a bit shorter but more cryptic since you do several things in a single line. This is bad for debugging (exceptions only tell you line numbers. If you do 5 things in a single line you have no idea what part failed). Also in most cases you usually need to do several additional things to the instantiated object or you want to store it in some kind of list to keep track of the object. In both cases you need an explicit local variable.


That variable does not have any impact on the performance.

Show more comments
avatar image FJPoort · Oct 15, 2014 at 12:29 PM 1
Share

This works perfectly GibTreaty! Answer should be accepted since it does exactly what is asked here

avatar image
0

Answer by Radon · Aug 03, 2012 at 06:40 AM

Your Gameobject's name is not changing. It is the system telling itself in the inspector that the original object is not a clone so you don't accidentally erase it. If you apply your code to a specific parent name or game tag, the script shall work on clones, too.

Comment
Add comment · Show 2 · 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 GibTreaty · Aug 03, 2012 at 06:42 AM 0
Share

He's not trying to Destroy the object, he's trying to rename it.

avatar image Radon · Aug 03, 2012 at 06:45 AM 0
Share

Oops .. ok I will fix it

Follow this Question

Answers Answers and Comments

15 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 avatar image avatar image

Related Questions

How to instantiate from prefab, not from instance? 3 Answers

Issues with tracking prefab instances and gameobject naming (JS) 1 Answer

Prefab instances not renaming when prefab is renamed? 1 Answer

Instantiated rooms don't function properly. 1 Answer

Affect All Instances Of A Prefab 3 Answers


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