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 NoSoup4you · Jun 02, 2015 at 07:25 AM · collidertriggerefficiency

General beginner question about collisions/triggers

I've just set up an invisible trigger in a doorway that checks for a collision with the player (if col.gameObject == dude...) and executes a music crossfade coroutine. No problems here, but I learned along the way that Unity's OnTriggerEnter checks for a collision with ANYTHING, and then you have to use ifs to narrow it down. My first instinct was to define a specific collider and use it as a parameter with OnTriggerEnter, which didn't work of course. This approach seems counterintuitive. For instance, if my invisible doorway collider is touching the walls and floor, isn't that going to waste CPU cycles? Or is it just as spendy as having a trigger hovering in midair? Do I need to care about that stuff?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by YoungDeveloper · Jun 02, 2015 at 07:34 AM

Collision and Trigger check should in most cases be placed once - on player itself. So you check them once, and not for each door separately. You can use tags, layer masks or script with data attached to it to filter what you need.

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 KoJix · Jun 02, 2015 at 07:38 AM

You can give your player a tag like Player and say in code:

     void OnTriggerEnter (Collider other){
         if (other.tag.Equals("Player")){
             Dosomething();
         }
     }

About a collider intersecting with multiple object. So far as I know, It wont be effecting anything this much you've to worry about it.

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 NoSoup4you · Jun 02, 2015 at 07:45 AM 0
Share

Is it cheaper to check for tag than gameObject? I only want it to react to one object anyway.

I don't know how expensive various operations are on the CPU, so I get paranoid about efficiency. It seems like if you had a lot of colliders in a level, there'd be a lot of wasteful checking for certain tags etc as they touch unrelated things.

avatar image KoJix · Jun 02, 2015 at 07:55 AM 0
Share

Tags are a easy and fast way to detect if your triggers are colliding with the right gameobject. Colliders will be seen as physics, physics rendered by the CPU will not have a lot of cost.

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

22 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

Related Questions

Can't click gameobject when over another trigger? 1 Answer

The character cannot pass through the trigger 3 Answers

Box Collider (Trigger) Efficiency Question 0 Answers

How do you detect which collider is triggered when you have multiple? 2 Answers

Which AI finding enemy script is more efficient? 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