Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 CDR2003 · Mar 03, 2014 at 01:08 PM · editorvisiblehandle

Keep my custom handle visible even if object is not selected?

I coded some custom handles for my component today, using UnityEditor.Handles and I realized that the handles are not visible if the object has not been selected. Is there a way to keep the handles visible even if there is no object selected?

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

Answer by whydoidoit · Mar 03, 2014 at 01:52 PM

Handles are not necessarily invisible when the object is not selected, but Gizmos are. If you want to draw something in the scene view at any time use the SceneView onSceneViewGUI delegate:

   SceneView.onSceneGUIDelegate += YourSceneGUIFunction;

This function can contain Handles etc.

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 CDR2003 · Mar 10, 2014 at 10:05 AM 0
Share

Thanks, we are using gizmos to draw those now :)

avatar image BaptisteB · Apr 12, 2020 at 11:44 PM 0
Share

is deprecated. Use SceneView.duringSceneGuiins$$anonymous$$d


Full example on how to render an handle (wire cube) below: using System; using System.Collections; using System.Collections.Generic; using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif public class CameraTrigger : $$anonymous$$onoBehaviour { public Color handleColor; } #if UNITY_EDITOR [CustomEditor(typeof(CameraTrigger))] public class WireBox : Editor { private CameraTrigger myTarget; private Transform targetTransform; private void OnEnable() { myTarget = (CameraTrigger)target; SceneView.duringSceneGui -= OnScene; SceneView.duringSceneGui += OnScene; } private void OnScene(SceneView sceneview) { if (myTarget == null) { return; } Handles.color = myTarget.handleColor; targetTransform = myTarget.transform; Handles.DrawWireCube(targetTransform.position, targetTransform.localScale); } } #endif

avatar image
5

Answer by mightyboat · Nov 08, 2017 at 08:21 PM

I had this same issue, and tried multiple methods, but couldn't get it to work.

Just so this thread is more complete, I thought I'd share what eventually worked for me.

This is a solution that uses an Editor script:

 using UnityEditor;
 using UnityEngine;
 [CustomEditor(typeof(ItemSpawnPoint),true)]
 [InitializeOnLoad]
 public class ItemSpawnPointEditor : Editor {
     // This function is called for each instance of "spawnPoint" in the scene. 
     // Make sure to pass the correct class in the first argument. In this case ItemSpawnPoint
     // Make sure it is a "static" function
     // name it whatever you want
     [DrawGizmo(GizmoType.InSelectionHierarchy | GizmoType.NotInSelectionHierarchy)]
     static void DrawHandles(ItemSpawnPoint spawnPoint, GizmoType gizmoType)
     {
         GUIStyle style = new GUIStyle(); // This is optional
         style.normal.textColor = Color.yellow;     
         Handles.Label(spawnPoint.transform.position, spawnPoint.name + "(ItemSpawnPoint)", style); // you can remove the "style" if you don't want it
     }
 }


ItemSpawnPoint is the component I want to have a label in the editor

Credits go to Unity Corgi Engine creator for this solution.

Comment
Add comment · Show 4 · 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 erlioniel · Dec 18, 2017 at 07:08 PM 0
Share

Thank you, i've spent a lot of time to find your answer and it is working perfectly!

avatar image Chronarch_ · Dec 19, 2017 at 04:50 PM 0
Share

Thanks! This is the best way I've found to do this. Works perfectly and super easy to implement!

avatar image RoyBarina · Aug 05, 2018 at 11:43 AM 0
Share

Did worked for me too. BTW to check if it's selected add this in the top of the function:

 bool selected = gizmoType == (GizmoType.Active | GizmoType.InSelectionHierarchy | GizmoType.Selected);


avatar image usernameHed · Jan 05, 2020 at 01:28 PM 1
Share

Hey, I would like to add a button to this label (I would like, when I click on the ItemSpawnPoint, to select the gameObject). I have tryed to use Handles.Button, but it don't work inside this function... any suggestion ?

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

27 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

How to prevent PositionHandle to become FreeMoveHandle when shift key is pressed 0 Answers

Gizmo for custom cylindrical camera 0 Answers

How to disable the default transform gizmo in editor? 1 Answer

Select un-selectable Objects with mouse. 1 Answer

How does Handles.Slider2D work correctly? 0 Answers


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