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:

NullReferenceException: Object reference not set to an instance of an object
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!

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.