• 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
1
Question by Foo-Byte · Nov 27, 2015 at 10:21 AM · collidertriggercolliderslayerstriggers

Does OnTriggerStay ignore layers?

My game has collectable/harvestable resources (food and so on). All of these objects are in their own layer ("Resources"). The player may have multiple units, which are all on the "Player" layer. Through the Project Settings > Physics settings, I have set the Resources layer to only interact with the Player layer. The collectable colliders are set as triggers. So far, so good.

With a single collectable, the OnTriggerEnter and OnTriggerLeave will trigger appropriately, and add slowly to the player's inventory until the resource is depleted or they move away.

The trigger area is larger than the 3D model, and it's possible for the player to be close enough to collect multiple resources at the same time. When this happens, the "first" collectable takes priority and the second will wait until the first has been depleted before the player can start collecting it. In this situation, OnTriggerStay will periodically poll to see whether it's OK to to begin collecting the second resource. This code all works and does what I want it to do.

The problem is that as soon as OnTriggerEnter is called on the second resource (by the collider on the Player layer), the log starts getting spammed by OnTriggerStay collisions by the terrain collider (which is on a separate "Water" layer that should not be colliding with Resources). Does anyone know why this would happen? It seems as if OnTriggerStay is reporting all collisions on all layers once the trigger collider has been activated. It's not breaking my code because I'm doing other checks, but I set up the layers and collisions to avoid unnecessary physics. What am I missing?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kblood · May 25, 2017 at 09:59 PM

I was wondering this myself. Came across this question, which is similar and has an answer that seems useful. http://answers.unity3d.com/questions/795821/exclude-ontriggerstay-with-certain-objects.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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Destroying objects within collision 1 Answer

changing gravity OnTriggerEnter 1 Answer

How to Specify a Collider in OnTriggerStay function? 1 Answer

Triggers? How do I use them to finish a game? 1 Answer

Problems with the Trigger Collider (randomly fictional) 1 Answer


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