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
2
Question by Filippopotamus · Mar 09, 2013 at 02:57 AM · physicscollidertriggerparentingrigibody

Triggers colliding when they are set not to in Collision Matrix

I have 2 objects. Player and Tower set to layers Player and Armory respectively. Both have rigidbodies. Each one has a child called Vision which is a sphere collider set to trigger and both visions are in a layer called Trigger. In the Physics inspector, I set the collision matrix NOT to collide between Trigger/Trigger but collide between Player/Trigger, Armory/Trigger.

So, I assume that those Vision triggers are not going to collide with each other. But they do. I get OnTriggerEnter/Stay/Exit between these 2 colliders which are in the same layer Trigger. Which is set not to collide.

Is the physics engine pretending that the Vision child of Player to be in the same layer of Player? And the same for the Vision child of Tower?

Is there a way to get around this?

Thanks in advance! Cheers!

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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by RyanZimmerman87 · Mar 09, 2013 at 03:19 AM

So far I haven't even used trigger functions whatsoever. Perhaps they will save you time if you use them properly but in my experience so far they are not necessary.

If you are having trouble getting them to work properly you could try something like this:

 void OnCollisionEnter(Collision theCollision)
 {
 
 //get the script for the object which you are checking collisions for example:
 
 ArmoryScript otherObjectsScriptArmory = theCollision.gameObject.GetComponent<ArmoryScript>();
 
 if (otherObjectsScriptArmory != null) //the script IS on that game object
 {
 
 //your desired behavior
 
 }
 
 }

Using something like that has allowed me to detect all collisions between objects as expected. In this example you would put this in your Player's script to detect if a collision occurs with a game object containing your Armory Script.

This method allows you to check for as many different collision types as you want all within one function.

Triggers may actually be the superior method but right now I prefer this.

This example is assuming the script attached to your tower is called ArmoryScript. You will need to adjust all the names to suit your project.

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 Filippopotamus · Mar 09, 2013 at 03:32 AM 0
Share

As far as I can tell, a script attached to a trigger will not get the 3 OnCollision events. It will get the 3 OnTrigger events. I don't know if I want to check the components like that either. That can be fine if you have a small number of component types to check against. But if there are a bunch, this can be very costly, especially for mobile.

avatar image RyanZimmerman87 · Mar 09, 2013 at 03:41 AM 0
Share

I agree the downside to this method is that it could be costly on performance. It seems like checking 3+ different components on my current Android project is not causing issues yet though.

I think if you use:

return;

within the different object checks and start with the most likely colliders it won't be to bad.

I just like this method because it's very easy to set up. I am curious how much of a performance difference it actually is with the trigger events.

avatar image
0

Answer by Filippopotamus · Mar 09, 2013 at 03:49 AM

I not familiar with the internals, but I would assume trigger would be quicker since they are mostly ignored by the physics engine since they don't react to each other.

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
avatar image
0

Answer by Loius · Mar 09, 2013 at 03:54 AM

Debug.Log your objects' layers and names in your trigger functions, to be sure everything's in the layer you expect.

You could also try making your player and its vision object children of a new, default-layer object, and see if that brings up collision issues.

If your player has a rigidbody/Controller, and your vision does not, AND your vision is a child of the player, it's possible that the entire collision tree is being set to the same layer as the rigidbody. The fix to that should be as simple as adding a kinematic rigidbody to each vision objects.

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
avatar image
0

Answer by MrMeows · Jun 11, 2015 at 09:01 AM

I have the same problem. It appears that triggers ignore the layer collision matrix. For your problem, I would do something like this:

void OnTriggerStay(Collider NewCollider)
{
 if(NewCollider.gameObject.layer != 10)
 {
  Function();
 }
}

...assuming that 10 is the layer index of your Vision GameObjects.

P.P. I just noticed when this was asked. Oops.

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

13 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

Related Questions

Child object's collider (on a different layer) is interfering with parent Physics... 0 Answers

Collider trigger only affecting a single game object when it should affect multiple 0 Answers

Layers, parenting and collisions. 0 Answers

How having correct bounce on a rotating pinwheel(it's more complicated)? 0 Answers

How do I stop the trigger effects once the player leaves the collider? 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