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
3
Question by jimbobuk · Dec 07, 2009 at 12:44 AM · proximity

Efficient spatial searching (finding game objects within a certain range)

I'd like to try and gather gameobjects in a spatially efficient manner such as

  • Gather all gameobjects within r radius of a point p

I was wondering what options were available for doing this, obviously spatial trees could be written in scripts but i'm presuming the performance could suffer a little versus some integrated built in solution.

Mike has suggested Physics.OverlapSphere() if the gameobjects have colliders.. I may consider going down this route though i had planned to NOT have colliders on these gameobjects. I wonder about maybe turning colliders on and off as required, only on for a short period whilst gathering entities. Though i'm sure PhysX won't appreciate having to recalculate its spatial trees, surely it'll still be quicker than trying to write your own?

Thanks

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

Answer by Ricardo · Dec 07, 2009 at 06:08 AM

I've done it both with octrees and using triggers. Actually doing it with triggers can put quite a burden, as triggers will fire not only for your spatial-interest objects but for any other collider in the scene. Depending on your implementaiton, you're also likely to end up keeping one proximity list per object, which ends up being updated every time an OnTriggerEnter and OnTriggerExit fires - hardly optimal.

I suggest you implement a simple octree and compare the performance against the physics-based version.

Doing the verification yourself, instead of leaving it to physics engine events, also has the advantage of control. It will allow you to:

  • Perform smoothing. If you update the proximity lists every time a relevant object enters or exits the proximity radius, you're likely to end up with a jittery behavior where the objects update their course/awareness too often.
  • Control when to update. If you have many objects on the scene, you likely won't want to update many of them several times per frame. Keeping a proximity database yourself will allow you to, for instance, perform round-robin proximity updates where you upgrade a single object's proximity list per frame, thus saving you processing time for other tasks.

Related answer.

Comment
Add comment · Show 1 · 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 cregox · Feb 09, 2012 at 03:46 PM 0
Share

related topic and updated link for the related "answer"

avatar image
2
Best Answer

Answer by Ashkan_gc · Dec 07, 2009 at 05:45 AM

i think the best approach is to use triggers in your gameobjects that you want to search for them and then use the physics.OverlapSphere function. triggers are not heavy and you don't need to implement OnTriggerEnter () or other functions for your solution to work. also you can create a big sphere collider(trigger) and then implement it's OnTriggerEnter and OnTriggerExit functions to see what objects are comming in and what objects are going out

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

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Audio Source AI Attractor 2 Answers

Having a door dissapear once a key is collected 1 Answer

How to import the object from server to unity 2 Answers

Setting Scroll View Width GUILayout 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