• 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 gzzhongqi · Oct 06, 2016 at 01:12 PM · collisionchild object

Handling collision in child object

I am just starting learning Unity and I am running into problems with compound colliders. I created an empty game object and added a cube as its child. I attach a rigidbody on the parent and a collider to the child. I attached scripts on both the parent and the child, but I can only seem to get collision events on the parent. I am really confused about this. (I tried adding a rigidbody to the child as well, but that seems to make the object falls right through the floor for some reason. The child does fire off an collision event in this case.)

Both the parent and the child has code like this: using UnityEngine; using System.Collections;

 public class test : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnCollisionEnter(Collision other)
     {
         Debug.Log("full collision");
     }
 }
 
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 bellicapax · Oct 06, 2016 at 03:32 PM 0
Share

You are right, colliders will only send messages to the $$anonymous$$onoBehaviours on the GameObject which holds the Rigidbody component.

There are a multitude of ways to work with this constraint. What are you trying to achieve?

avatar image gzzhongqi bellicapax · Oct 06, 2016 at 03:43 PM 0
Share

I have a parent game object that is made up of multiple child primitive objects (cubes to be exact). When a collision happen, I want to find out exactly which child actually caused the collision. Tagging isn't an option for me because the number of child would be dynamically changing during runtime. It would be also a mess for me to try to handle it from the other collision object as well, since for that part I am using a existing unity packet and I want to refrain from changing their code. What can I do in this case?

1 Reply

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

Answer by Raresh · Oct 06, 2016 at 04:02 PM

From what I understand you want multiple children in an object, and detect collisions individually for the children. For that you need to attach a rigidbody to each of the children. Otherwise the collisions will go up the hierarchy and register at the first rigidbody. :)

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 gzzhongqi · Oct 06, 2016 at 04:09 PM 0
Share

I need a rigidbody at the parent object as well. (Again I am new to Unity. I am assu$$anonymous$$g this is necessary to maintain the shape of the whole object. If I don't have a rigidbody at the parent, the whole object falls apart) When I tried giving the child a rigidbody as well, it seems to give me weird behaviors. For example, when I drop it on the ground, although I gets the desired collision event from the child, the object passes right through the ground. How can I fix this?

avatar image Raresh gzzhongqi · Oct 06, 2016 at 04:17 PM 0
Share

You can have a rigidbody on the parent as well, just don't expect it to call OnCollisionEnter.

Falling through objects, especially at high speeds is not a 'weird behaviour'. It's just how physics work. Imagine, the physics has a fixed timescale. If the object A is moving too fast, between the frames there is a chance the object will miss object's B collision box (happens mostly with flat collision meshes).

So you either A) Slow things down, B) Set collision detection to Continuous (uses a little more resources), C) Use a cube ins$$anonymous$$d of a plane, D) Write your own custom logic (raycasts etc)

avatar image gzzhongqi Raresh · Oct 06, 2016 at 04:48 PM 1
Share

Thanks. I will try that out.

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

How to detect collision on child, if parent has RigidBody? 0 Answers

Moving children objects with parent 1 Answer

make OnCollisionEnter2D ignore collisons of child objects 0 Answers

Snap with collision trigger on child objectss 1 Answer

How can I get Compound Colliders to work properly? 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