Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 sinoby · Sep 08, 2014 at 08:23 PM · rigidbody2danimator controllerchild object

De-attach child from parent and remove from animation

Hi All!

I have a GameObject with some child objects and a animator controller for parent object, in animator I move childs by curves and on keypress I need to deattach 1 child object from parent and this child should not be used in animation any more.

I do transform.parent = null for child and there are two cases:

  1. if child do not have RigidBody2D it appears at coordinate center and update position by animation in keypress

  2. if child have RigidBody2D it appears at coordinate center and still move by animator

so how to fully deattach child and remove them from animator process? and leave deattached child on old world position?

P.S child should be with rigidbody2d all time

version 4.5.0f6

thanks

I think that i find answer, use a Animator.Rebind

Comment
Add comment · Show 3
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 juhopekka · Sep 23, 2014 at 07:11 AM 0
Share

Hi,

I have exactly the same situation:

Child objects are animated my the Animator at the parent. At some point an event triggers detaching one of the child object (with child.transform.parent = null) which continues to fly across the scene. Now, the only problem is, that it seems that the child is still affected by the animator at the parent..

How did you remove the detached child from animating, while rest of the gameObjects are animated?

Thanks.

avatar image juhopekka · Sep 23, 2014 at 07:33 AM 0
Share

Ok, I get it now.

Just after setting child's parent to null, use animator.Rebind(), so that the animation is "refreshed" and the detached child is no longer part of the animation :)

avatar image sinoby · Sep 24, 2014 at 02:06 PM 0
Share

yes, animator.Rebind() helps, only one bad thing that animation stars from beginning after it.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by modegames · Jul 27, 2015 at 04:42 AM

I found this function we use helps to resolve this issue

 public static void RemoveObjectFromAnimator(GameObject gameObject, Animator animator)
         {
             Transform parentTransform = gameObject.transform.parent;
             
             gameObject.transform.parent = null;
 
             float playbackTime = animator.playbackTime;
             
             animator.Rebind ();
             
             animator.playbackTime = playbackTime;
 
             gameObject.transform.parent = parentTransform;
         }
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 lokihornsby · 6 days ago 0
Share

Thankyou - brilliant solution!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I make a child RigidBody be stuck to a parent RigidBody (Unity2D) 1 Answer

Moving children objects with parent 1 Answer

Move/Rotate Kinematic (2D) Child with MovePosition/MoveRotation Doesn't Work 0 Answers

Issue with Animating MultiPart 2D Character with RigidBodies 0 Answers

Is it okay to give child objects rigidbodies? 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