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
0
Question by hav_ngs_ru · Oct 18, 2014 at 06:34 PM · collidertriggerontriggerenterintersection

Check if something enters my trigget withowt OnTriggerEnter

Could I wheck if something enters my trigget withowt OnTriggerEnter? The goal is to avoid using OnTriggerEnter, in cases when I want to check intersection just once or twice during my level.

I have a lot of triggers that needed to be checked very rarely, and I trying to find a way to remove all controllers (that just has OnTriggerEnter and changes one public var) and just check the intersection of trigger by specified object from outside. Does it exists?

PS. collider.bounds.intersects() is too rough for my case.

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
Best Answer

Answer by tanoshimi · Oct 18, 2014 at 06:40 PM

No. By definition, the only way you can act the moment something has entered your trigger (however rarely that may occur) is to check every frame, and that's what OnTriggerEnter does.

If you want to disable trigger checking based on some condition (e.g. perhaps don't bother checking when all triggering objects are a long distance away), you can disable the script component containing the OnTriggerEnter, and then re-enable it again when the potential triggering object(s) gets close. But then that requires adding a distance check and the overhead of enabling/disabling the component, so it might not be worth the effort.

Comment
Add comment · Show 6 · 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 hav_ngs_ru · Oct 18, 2014 at 06:50 PM 0
Share

thank your for your answer. but I`m realy puzzled, why so. Unity definitely hav some code that it used every frame to detect the intersections... why not let game-developers use them too when it needed, and avoid per-frame calls of it?

avatar image tanoshimi · Oct 18, 2014 at 07:00 PM 0
Share

There is no one-shot "Has anything entered this trigger in this frame?" method. Nor is there a (potentially more useful) one-shot "Is anything currently inside this trigger?" method. That's just how it is. Have you reason to believe that per-frame collision detection is causing a significant performance hit in your code?

avatar image hav_ngs_ru · Oct 18, 2014 at 07:14 PM 0
Share

there is widespread belief that a lot of objects with OnTriggerEnter method is bad in terms of performance. Unfortunately, I have no proof nor disproof yet, I just respect this popular opinion :)

avatar image tanoshimi · Oct 18, 2014 at 07:30 PM 1
Share

Well, the colliders of every gameobject in your scene are exposed via the API, so there's nothing to stop you writing your own collision-checking functions.

avatar image Habitablaba · Oct 18, 2014 at 07:40 PM 0
Share

I'm not sure how 'widespread' that belief is @hav_ngs_ru
OnTriggerEnter really shouldn't bog down performance at all. What, if anything, would cause the performance hit would be a lot of objects with complicated colliders on them (like mesh colliders ins$$anonymous$$d of sphere or box).

Show more comments

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

27 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

Related Questions

Colliders that do not collide... 1 Answer

OnTriggerEnter not being called with multiple colliders 1 Answer

How to not trigger its own collision box? 0 Answers

OnTriggerEnter 1 Answer

Make object react to certain triggers only 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