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 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

avatar image Bunny83 olumide · Nov 11, 2014 at 09:29 PM 0
Share

First of all this doesn't really answer the question at the top, so this shouldn't really be an answer. Second if your passenger wasn't a child of another object before you made it a child of the train, the parent of the passenger was null. Setting the passenger's parent value to null will detach the passenger from the train and it can move on it's own again. Saying "didn't work" isn't a proper explanation of what happens or what exactly didn't work.

You were told to just set the parent to null. It seems you've added this strange line:

 objectA.tranform.parent = objectA.transform;

which makes no sense at all. The object can't be a child of itself. The parent variable builds a hierarchy tree. If an object doesn't have a parent it's at the top of that hierarchy and doesn't depend on anything else.

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.

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

Separate child rotation 1 Answer

Assign parent object to target 2 Answers

Object scale/rotation changes when parented to flipped object 0 Answers

Instantiate a Prefab as child 0 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