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 luiscmendez · Jul 10, 2013 at 05:33 AM · parentingridigbodyunparenting

Parenting and Unparenting a GameObject that has a Rigidbody

Hey, everyone. I've got moving platforms in my side scrolling game. I parented my character GameObject to it so that it stays on when it moves up and down and left to right.

The moving platform has a box collider parented to it and set as a trigger. When I step onto the platform the character parents to the platform, but when I exit or get off of the platform it never unparents and the Debug.Log never shows up for OnTriggerExit.

I've tried changing the parenting from OnTriggerEnter and OnTriggerStay, but seeing as how parenting isn't the issue it doesn't do much. The problem is that for some reason it never detects the GameObject exiting the trigger. The character has a rigidbody component attached to it and when I remove it, it unparents and parents perfectly.

Am I missing a step here? How do I get the object to parent/unparent while still having the rigidbody component?

Here's the javascript code down below:

 #pragma strict
 var player : GameObject;
 var platform : GameObject;
 
 function Update()
 {
 
 }
 
 function OnTriggerEnter(other : Collider)
 {
     //if the colliding gameobject is the player...
     if(other.gameObject == player)
     {
         player.transform.parent = platform.transform;
         Debug.Log("Parented");
     }
 }
 
 function OnTriggerExit(other : Collider)
 {
     //if the colliding gameobject is the player...
     if(other.gameObject == player)
     {
         player.transform.parent = null;
         Debug.Log("Unparented");
     }
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by bruce965 · Jul 10, 2013 at 04:00 PM

Collisions are disabled between an object and it's parent, OnTriggerExit is never called because collisions are not checked anymore after you have parented player GameObject.

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 luiscmendez · Jul 10, 2013 at 05:08 PM 0
Share

Oh ok. That makes sense. Thanks for your help. I'll have to figure out a workaround then.

avatar image TruffelsAndOranges · Jun 20, 2015 at 08:36 PM 0
Share

Found any workaround for this?

avatar image
0

Answer by jakelong00 · Apr 03, 2014 at 07:14 PM

Try Transform.DetachChildren on the platform

 http://docs.unity3d.com/Documentation/ScriptReference/Transform.DetachChildren.html
Comment
Add comment · 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

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

17 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

Related Questions

Creating a function that parents player to object and then unparents it 1 Answer

Buggy child parenting/unparenting? How to avoid For-Loop wackiness? 3 Answers

Unparent object on collision? 3 Answers

parent player to object when you press a button a set amount of time 1 Answer

How can I de-parent an object from another?? 4 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