• 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
2
Question by George · Oct 23, 2010 at 09:51 AM · editorsceneviewgizmosgizmohandles

Select object by selecting gizmo or handle?

Is it possible to select a gameobject by selecting the gizmo in the Scene View? I have a line (Gizmos.DrawLine) between object A and object B and I want to be able to select the line and have it select object A.

That then leads on to my second question to grab a MouseOver event from gizmos, but maybe i'll leave that for another Question.

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 Tom 17 · Apr 19, 2011 at 01:12 PM

This question is old, so I don't know if I will be of help anymore, still I'm going to answer.

I don't know if gizmos are meant to be selectable, but on the other hand there is the possebility of extending the Unity Editor itself (refer Extending the Editor). There you get the idea of how to use handles to easily modify certain aspects of your object A.

That doesn't help you on your specific question, as basically to see the handles you would have to have your object selected allready. So as another straw for to hold on here is a small editor script that automatically selects the parent of something selected in the scene or hierachy view:

using UnityEditor; using UnityEngine; [@CustomEditor(typeof(AutoSelectParent))] public class AutoSelectParentEditor : Editor { public override void OnInspectorGUI() { EditorGUILayout.TextArea("You should not see this text unless this script doesn't work"); }

 public void OnSceneGUI()
 {
     MonoBehaviour handle = (MonoBehaviour)target;
     GameObject[] selection = new GameObject[1];
     selection[0] = handle.transform.parent.gameObject;
     Selection.objects =  selection;
 }

}

put that script in an Editor folder for it to work. The following script is rather a marker to objects that shall not be selected. Put it outside an Editor folder and attach it to an object. Whenever you try to select object C that is a child of object A, you will instead select A immediatly. This can become a nuisance if you DO want to select object C again. To do that type the name ob object C in the search filter of the scene view to exclude the parent and you CAN select object C again.

using UnityEngine; public class AutoSelectParent : MonoBehaviour { }

Maybe you get some different ideas from the hints I gave you - if you do ponder this problem anymore, anyhow :-)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Why does this function, when called from OnDrawGizmosSelected, produce a different result and kill the editor? 1 Answer

Constantly Update Scene View 1 Answer

box gizmo with scale handles 0 Answers

How to make a custom gizmo like 'Grid' or 'Axis'? 0 Answers

Drawing A 2D Capsule (Same of CapsuleCollider2D) 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges