Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 xarismax · May 10, 2018 at 10:52 AM · collisionphysicstriggerlayers

Trigger Colliders: adding/removing rigidbody/collider at runtime is unreliable or confusing

I have a simple script:

   public class TrackingTrigger : MonoBehaviour
   {
   public List<Transform> Inside = new List<Transform>();
   void OnTriggerEnter(Collider other)
   {
      Debug.Log("Enter: ("+this+", "+ other+")");
      Inside.Add(other.transform);
   }
   void OnTriggerExit(Collider other)
   {
      Debug.Log("Exit: ("+this+", " + other+")");
      Inside.Remove(other.transform);
   }
   }

I Create the scene as follows:

   P: Parent GameObject 
   A: Child GameObject Under parent P
   B: Child GameObject Under parent P
   I add TrackingTrigger, SphereCollider, RigidBody in all three (P,A,B) and hit play. It works as expected: each Trigger has inside it all that collide.

1) Test Case: Non Symmetry

   a) Remove B.SphereCollider : OnTriggerExit is not called at P,A,B
   b) Add B.SphereCollider : OnTriggerEnter is called
   Problem: 1a => not symmetric behaviour => Objects are "double added" in lists

2) Test Case: Mindblow

   a) Remove B.RigidBody: causes OnEnter: (A,B) (P,A) (B,A)
   Problem1: "Exit" is never called, instead "Enter" is called
   Problem2: Since B has no rigidbody it attempts to use his parent P rigidbody, but why is A affected ? ie (P,A) makes no sense, it doesn't even cause (A,P) symmetrical callback.
   b) Add B.RigidBody: causes Exit: (A,B) (B,A) Enter: (A,B) (B,A) (P,B) (B,P)
   Final Lists: 
   P={B,A,A,B}
   A={P,B,B}
   B={P,A,A,P}

3) Another issue i had with trigger colliders is that in unity every trigger, checks for all nearby colliders, there is no way to filter "triggers" by layer (without lowering performance). So i cannot use "Collision Layer Matrix" optimizations.

4) To me all this seems confusing. I am testing the system to its limits to understand how the api "works". I was thinking of using this for a system where big triggers get "refined" into smaller triggers when something gets inside them for ultra detailed physics. I don't want to monopolize your time, only answer if it doesn't take much time, I can figure things on my own, if you point me to the right direction. thank you

Comment
Add comment · Show 4
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 tormentoarmagedoom · May 10, 2018 at 11:06 AM 0
Share

wow, very good post. Order, everything explained.... but... I have no *** idea how can i help you :( (or too complex or too lazy)

avatar image Captain_Pineapple · May 10, 2018 at 07:59 PM 1
Share

Hey there,

i was raised in Unity with the knowledge never to parent Rigidbody together as seen for example in this Post. Aparently that is not valid anymore. Good to know :D o far intresting Problem. I think i'll try to reproduce that myself. Did you check if it is related to the parenting or does the same issue occure if you undo all or parts of the parenting? I'm asking since im currently facing a somewhat similar weird behaviour which utilizes pretty much exactly the same script that you use. I posted it here.

avatar image Vicarian · May 10, 2018 at 10:09 PM 0
Share

Entry is a bit frustrating for just this application. I tossed it and started using OnTriggerStay with a boolean to only check once to make sure that an Enter trigger is actually valid.

avatar image iJuan · May 12, 2018 at 05:32 PM 0
Share

Rigidbodies treats colliders as a whole. When you remove B's Rigidbody, B collider joins to P Rigidbody, which updates that Rigidbody, that's why OnEnter is being called.

Using rigidbodies in parents and childrens is delicated, though, it's not forbidden. Ragdolls uses lots of rigidbodies trough all it's hierarchy as an example

1 Reply

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

Answer by xarismax · May 12, 2018 at 04:58 PM

thanks for the answer. Solution given by Captain_Pineapple Comment.

"you cannot have rigid body on both parent and child".

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

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

Does the "Layer Collision Matrix" affect triggers? 1 Answer

How to achieve this basic physics effect? Detect when to change layers 2 Answers

Wind physics script 1 Answer

If trigger hit, spawn it 1 Answer

Collission and Trigger on Same object 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