- Home /
Using Handles class
How can I use the Handles class in an editor window to show a Vector3 point in the scene view?
I simply want to be able to enter co-ordinates and have a handle appear there.
I've got this so far:
class SimpleHandle extends EditorWindow{
private var posValue : Vector3;
@MenuItem ("Window/Simple Handle") static function Init () { var window : SimpleHandle = EditorWindow.GetWindow(SimpleHandle); }
function OnGUI(){ posValue = EditorGUILayout.Vector3Field("Position", posValue); }
function OnSceneGUI () { Handles.PositionHandle(posValue, Quaternion.identity); }
}
But it doesn't work, and looking through the forums and documentation hasn't helped - examples in the docs are pretty sparse with the Handles class...
Thanks!
Answer by yoyo · Jan 05, 2011 at 04:05 PM
Old question, so you've probably figured it out already, but anyway ...
EditorWindow doesn't have an OnSceneGUI method, so your code above will never get called. You can do what you want in a custom Editor, but not an EditorWindow. For an Editor, the OnSceneGUI method lets you draw into the scene view, which is where the Handles class becomes useful.
Typically the OnSceneGUI method would be used to draw things in the scene relative to the target object of the Editor (the component being edited), but there's nothing to stop your Editor from having its own member variables and drawing whatever it feels like.
Note that Editor.OnSceneGUI will only be called when the editor is active in the Inspector, which may not be what you're looking for.
MonoBehaviour.OnDrawGizmos may be a simpler solution to what you're trying to do. You could have a component with an array of Vecto3's, and have its OnDrawGizmos method draw a handle for each of the vectors.
Answer by Seneral · Nov 20, 2014 at 07:06 PM
To just slightly change your code I would suggest to add
void OnEnable () {
SceneView.onSceneGUIDelegate += MySceneFunction;
}
and also
void OnDisable() {
SceneView.onSceneGUIDelegate -= MySceneFunction;
}
I still don't know how to add delegates similar to OnDrawGizmos() , which I was searching for at the moment. -Seneral
Your answer
![](https://koobas.hobune.stream/wayback/20220613061930im_/https://answers.unity.com/themes/thub/images/avi.jpg)