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 /
avatar image
0
Question by transplanar · Mar 17, 2012 at 12:12 AM · prefabsinstantiation

Unable to remove (Clone) suffix (with a possibly a related instantiation issue)

I am trying to create a new instance of a prefab, but it keeps appending the "(Clone)" suffix to the end of the new copies. I tried looking at similar questions, but none of them matched what I was trying to do.

Here's the code I'm working with:

 void generateChain(){
         GameObject newChain = Resources.Load("ChainPrefab") as GameObject;
         Rope2 newScript = newChain.GetComponent<Rope2>();
         newScript.PointA = GameObject.Find("Sphere");
         newScript.PointB = GameObject.Find("Point B");
 
         newScript.ropeDetail = (int) Vector3.Distance(GameObject.Find("Point B").transform.position, GameObject.Find("Sphere").transform.position);
         Rope2.AttachPoint spherePosition = new Rope2.AttachPoint();
         spherePosition.attachedObject = this.gameObject;
 
         newScript.attachedObjects.Clear();
         newScript.attachedObjects.Add(spherePosition);
                                       
         Instantiate(newChain);                
         newChain.name = "Chain";
     }

As you can see, at the end I do change the newChain GameObject's name to "Chain," but this doesn't do anything.

On a possibly related note, am I instantiating a new copy of the prefab correctly? I wonder because as you see above I modify some of its scripts prior to instantiating, as the chain itself is rendered upon instantiation, and needs to be set up prior to then. Is this the correct way to go about that?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Mar 17, 2012 at 12:14 AM

 var nc = Instantiate(newChain);          
 nc.name = "Chain";
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 transplanar · Mar 17, 2012 at 03:02 AM 0
Share

Getting closer. That solves the issue of Chain's name, though now I'm still having an issue where the rope generated in association with the chain object is being named "Chains(Clone)_Rope". The rope is named with the following code:

   ropeObject = new GameObject(transform.name + "s_Rope");

It is part of the RopeScript made by Reverie Interactive here. I tried changing that code to:

 GameObject tempChain = Instantiate(newChain) as GameObject;          
 tempChain.transform.name = "Chain";

But this didn't seem to fix it. Is there some other part of the object that needs to be renamed for it to work properly?

avatar image Bunny83 · Mar 17, 2012 at 03:38 AM 0
Share

@transplanar: Where do you create the ropeObject? In a script that is part of the chain prefab? If that's the case make sure you do it in Start() and not in Awake().

Awake is called even before Instantiate() returns so you have no chance to rename the object from outside. Another way (which is the best i guess) is to rename the object from an attached scripts Awake function.

 void Awake()
 {
     name = "Chain";
 }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Instantiating Prefabs from a MonoBehaviour-derived class using an array -> compiling but not rendering [SOLVED] 0 Answers

Tutorial for manual instantiation of prefabs yields null exception 2 Answers

Need help understanding scripted prefab behavior - when I click one, the script runs on ALL prefab instances, not just the one I clicked. 3 Answers

Is it necessary to assign the result of Instantiate() to a variable and is there a need to always typecast? 1 Answer

How can I create a prefab variant in C# script? 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