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 Tyson.9 · Nov 17, 2011 at 05:06 AM · editorcolliderselectionsceneview

Unity Editor style selection in game

I need a way of performing the same super accurate selection behavior that the Unity IDE exhibits when using the Scene view and clicking on any visible object.

This functionality is required for a non-gaming project, and the majority of the scene contents is generated from user data. 50k objects is realistic.

I have tried a few approaches. All involve ray casting from the screen click point:

1) For each generated object with a mesh, also add a MeshCollider. This is quite slow (takes 10 minutes when doing 50k), and for some reason the ray-casting quite often misses certain meshes (usually pipe like cylinders).

2) Use BoxColliders instead. This is faster to add, and never misses a raycast, but obviously causes a mis-match between the visible shape and the clickable area. This causes problems when trying to select objects behind other objects, but the box collider of the object in front is in the way.

But if I go into the Unity IDE Scene view after generating all these objects, selection works perfectly. The Unity IDE only has access to the same information as me (the meshes) so it must be possible.

So firstly, does anyone know what approach Unity takes for selection under the covers in the IDE? Secondly, and preferably, is there any way to access this via APIs so I don't have to redo work.

I'm thinking they use some triangle -> mesh map where every time a mesh is added, all the triangles it contains are added to some global map that points back to that mesh. Then the ray cast only has to find the first triangle intersected, and the map points to the containing mesh, and hence object. But that is an uneducated hunch and I'm not even sure searching for intersections between triangles and lines is efficient, or how to do it.

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 aldonaletto · Nov 17, 2011 at 12:05 PM

I don't know how Unity scene raycast works, but I suppose that this triangle approach can be too slow. I have a suggestion: use box colliders, but do a RaycastAll instead of a simple Raycast - this will return an array of RaycastHits containing all objects hit by the ray. Since the number of objects in this first selection is relatively small, for each RaycastHit in the array you could replace the object's box collider with a mesh collider and do a raycast from hit.point (use the same ray, but change the ray.origin); if the object hit's transform == hit.transform, this is the object clicked; if the transform is different, the actual body was not hit, thus repeat the procedure for the next RaycastHit.
Well, I have not tested this, but I suppose it could work - or at least help you to find a solution.

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 Tyson.9 · Nov 17, 2011 at 12:46 PM 0
Share

Thanks, but the slowness of $$anonymous$$eshColliders was not the only reason I was avoiding them. They also seem to miss hits when the mesh is a skinny cylinder shape (But clicking that same mesh within the Unity IDE works perfectly).

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to select prefab children in scene view 1 Answer

Is it possible to draw gizmos when an object is selected, but not when the parent is selected? 2 Answers

Unable to select anything on the Scene window by clicking 2 Answers

Auto-Selecting something else in Scene-View? 0 Answers

How can I set a selection-sphere in the editor 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