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
1
Question by TheCodeMonkey · Mar 26, 2012 at 12:00 AM · physicscollidertriggercollisions

Find all objects currently colliding with trigger

Lets say I have a simple sphere collider that I am using as a trigger for an enemies vision radius. Is there a way to quickly get an array or list of all the colliders currently colliding with that trigger or within it?

Currently the only way I can think to do this would be to maintain my own list on the object using OnTriggerEnter and OnTriggerExit. However I am assuming I have simply missed a function that does exactly this when I looked through the script reference for it. I also could use Physics.overlapsphere however that would result in me having to place hard coded values within the script and I would much prefer to simply be able to call the trigger sphere collider I already have attached to the object and then acquire a list or array of colliders to work with.

Thank you in advance for any help.

Comment
Add comment · Show 3
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 by0log1c · Mar 26, 2012 at 12:14 AM 0
Share

I'm afraid you'll have to maintain your own list from the OnTriggerEnter/OnTriggerExit or use one of the Physics functions (whose parameters could be read from a given Collider).

avatar image TheCodeMonkey · Mar 26, 2012 at 12:24 AM 0
Share

Collider[] colliders = Physics.OverlapSphere(visionRadius.center,visionRadius.radius);

was the solution I ended up going with, I actually completely forgot I could simply use the sphere collider attatched to the object in the script. Thanks.

avatar image Argenex · Apr 17, 2012 at 02:31 AM 0
Share

I have an issue where I have a trigger that triggers an event on NPCs when they enter it. I cant put them into an array as they might 'die' while still being 'in the array' and we all know the madness of missing references due to the array silliness, so what I want to do is just "hey who is currently touching my collider". is there anyway to do this at all or are we stuck to Enter/Exit and Stay is unreliable due to its being set on certain frames...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rutter · Mar 26, 2012 at 12:26 AM

I also could use Physics.overlapsphere however that would result in me having to place hard coded values within the script

Not necessarily: you could access your trigger collider to use its position and radius as parameters for the call.

Like BY0LOG1C said, though, you may want to consider using the enter/exit functions provided by the trigger itself.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Collider/trigger collision causing physics glitch 0 Answers

Inconsistent Trigger events 1 Answer

overlapsphere to destroy NPCs on exit 1 Answer

Collider Lifts me off Ground ??? And I'm afraid of heights !!! 1 Answer

Prevent shooting when gun is inside wall 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