- Home /
Using PositionHandle inside an EditorWindow
In the OnGui() method I can call the PositionHandle method, which will create a new 2d handle, but I can't click it and the following error is being thrown:
UnityEditorInternal.FreeMove.Do (Int32 id, Vector3 position, Quaternion rotation, Single size, Vector3 snap, UnityEditor.DrawCapFunction capFunc) (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/EditorHandles/FreeMove.cs:184) UnityEditor.Handles.FreeMoveHandle (Vector3 position, Quaternion rotation, Single size, Vector3 snap, UnityEditor.DrawCapFunction capFunc) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/EditorHandles.cs:192) UnityEditor.Handles.DoPositionHandle_Internal (Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/EditorHandles/PositionHandle.cs:86) UnityEditor.Handles.DoPositionHandle (Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/EditorHandles/PositionHandle.cs:61) UnityEditor.Handles.PositionHandle (Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/EditorHandles.cs:93) Any idea? I don't want to re invent the wheel if I can avoid it. Thanks!NullReferenceException: Object reference not set to an instance of an object
Answer by Bunny83 · Nov 28, 2015 at 10:30 PM
The Handles class isn't ment to be used inside an EditorWindow. It requires an active Camera to work. An EditorWindow doesn't have a camera by default. You have to create a camera and use Handles.SetCamera before you use anything else from the Handles class inside an EditorWindow.
Your answer
![](https://koobas.hobune.stream/wayback/20220613145000im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
EditorWindow & Handles Position/FreeMove/... 1 Answer
Draw Gizmos and Handles in the scene from an EditorWindow 1 Answer
Code executes more than once when key press event is triggered in OnGui in Custom Editor Window 3 Answers
Huge Performance difference between docked and undocked EditorWindow 0 Answers
How to draw button in editor window rotated by 90 degrees? 0 Answers