Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by beisoftstudio · Oct 30, 2018 at 01:46 PM · unity 2dclonebreakinsantiate

how to break connection between gameobject and its clone in unity.

Hi, i have boxes gameobject and its children. Before i rotate or move this object, i insantiate all of them with using Record() method and if user want to take back action with using Undo() method, all objects including its clones is destroyed, so i dont want to destroy clone objects. how to break connection between gameobject and its clone. Sorry for my english thanks in advance. Here is the code

  public Gameobject boxes, boxesCopy;
     public void Record(){
             if (boxesCopy != null) {
                 Destroy (boxesCopy);
             }
             boxesCopy=Instantiate(boxes);
             boxesCopy.SetActive (false);
         }
     public void Undo(){
             Transform[] realChildren = boxes.GetComponentsInChildren<Transform>();
                     foreach (Transform child in realChildren)
             {
                 Destroy (child.gameObject);
             }
             Transform[] copyChildren = boxesCopy.GetComponentsInChildren<Transform>();
             foreach (Transform child in copyChildren)
             {
                 child.transform.parent = boxes.transform;
                             child.SetActive (true);
             }
         }

 
     
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
0
Best Answer

Answer by lacroix_math · Oct 30, 2018 at 02:13 PM

hi, there is probably numerous ways to do, but for me, it's simple. To attach an object, you do.

public bool if_Is_True;

Void Update() { if ( if_Is_True == true) { object_1.transform.parent = _player.transform // will attach object_1 to _player.. } else {
object_1.transform.SetParent(null); // will detach object_1 from _Player. }

So if you want to detach an object, juste add. object_1.transform.SetParent (null).

it work perfecly fine for me, to detaching trees from the base log, or Player to a Cart and moving both together.

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 beisoftstudio · Oct 30, 2018 at 04:45 PM 0
Share

Thanks, but i mean that i insantiate a gameobject which is existing already in my tree and if i destroy it and then its clone is also destroying or i change gameobject localscale and then clone's localscale is changing, there is a bound between them, i want to break its connection. I hope i could tell what my problem is

avatar image beisoftstudio · Oct 31, 2018 at 10:58 AM 0
Share

Sorry i found where i did mistake, GetComponentsInChildren finds children and its parent so i destroy parent too in old case and trying to attach it other children. i did like that and there is no problem. Thanks Transform[] realChildren = boxes.GetComponentsInChildren(); foreach (Transform child in realChildren) { if (child.gameObject.name != "boxes") { Destroy (child.gameObject); }

             }

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

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

Related Questions

Not being able to destroy clone of prefab. 0 Answers

Why Original GameObject Destroy Clones ? 0 Answers

Stop Infinitely Spawning Object on Javascript 1 Answer

[SOLVED] How to destroy a cloned object if it object colliding with another cloned object ? 1 Answer

Clones not using animator and enabling scripts? 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