• 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 olumide · Nov 08, 2014 at 12:56 PM · transformparentchildtransform.parent

undoing parenting of object's transform

I made the transform of objectB the parent of objectA, to enable object A move along with objectB. As shown below

objectA.transform.parent = objectB.transform

Now, there is need to reverse the process, so that objectA can move on its own.

Regards

Comment
Add comment · Show 2
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 olumide · Nov 11, 2014 at 09:07 PM 0
Share

@AlwaysSunny: A passenger enters a train and at a particular point, the train stops for the passenger to alight. When she enters the train, I decided to set her transform to that of the train, then there is need to reset her transform back, so that she can alight and move separately from the train. this was my reason for using the term parenting and un-parenting.

Setting the transform to null did not work. And if decided to detach the children- using objectB.transform.DetachChildren(), It would detach all the children, which is not what I want.

Though i have found a way round it, though not the best result for me. i decided to set the vector controlling the movement-speed, direction. for both the train and the passenger to the same. So they both move together, and at stopping point, the passenger was able to alight.

I believe there should be a better way of handling this.

Regards Olumyde

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Itaros · Nov 08, 2014 at 12:56 PM

 objectA.transform.parent = null
Comment
Add comment · Show 3 · 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 olumide · Nov 10, 2014 at 05:23 AM 0
Share

Thanks a lot

Using null actually delete the transform, but when i tried reverting back to the previous transform, that is the original transform of objectA, It was still attached to object B

objectA.transform.parent = objectB.transform

later,

objectA.tranform.parent = null;

objectA.tranform.parent = objectA.transform;

avatar image AlwaysSunny · Nov 10, 2014 at 05:25 AM 2
Share

Why would you attempt to set a transform to be its own parent? That makes no sense. Neither does this comment - I have no clear picture of your scenario or problem. Please consider revising your phrasing using proper jargon.

avatar image Bunny83 · Nov 10, 2014 at 06:00 AM 1
Share

@olumide: I don't get that either. Setting the parent of an object to null won't delete or destroy anything. It just makes the object a root object without a parent. Also, like AlwaysSunny said, you can't set the parent of an object to itself. That doesn't make much sense.

avatar image
-1

Answer by SmalleeStudio · Nov 10, 2014 at 05:29 AM

 objectB.transform.DetachChildren();
Comment
Add comment · Show 1 · 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 Kiwasi · Nov 10, 2014 at 05:38 AM 1
Share

While it will work, this will remove the parent from all children. Probably not what the OP intended.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

Make a GameObject child to a "Dragged Reference" GameObject doesn't work! 0 Answers

Properly Rotating Child Objects by Script 1 Answer

Creating new Transform from existing objects Transform to Instantiate object 1 Answer

Destroy(transform.root.gameObject ); 2 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