DrawCamera and Gizmos in EditorWindow


How do I draw Gizmos in the Handles.DrawCamera render? It says in the documentation that it would draw gizmos and handles in the returned render, but with no luck… here is the code:

using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;

public class TileEditor : EditorWindow {
	private const int __sideBarWidth = 200;
	private Camera __camera;
	private Tile __selectedTile;
	[MenuItem("Level Designer/Tile Editor... %k")]
	public static void ShowTileEditor() {
		TileEditor window = EditorWindow.GetWindow<TileEditor>("Tile editor");
		window.autoRepaintOnSceneChange = true;
	[MenuItem("Level Designer/Tile Editor... %k", true)]
	private static bool ShowTileEditorValidator() {
		return true;
	private void OnFocus() {
		this.__selectedTile = SectionEditor.selectedTile;
		if (this.__selectedTile != null) {
			this.__camera = EditorUtility.CreateGameObjectWithHideFlags("editorCamera", HideFlags.HideInHierarchy, typeof(Camera), typeof(Light)).GetComponent<Camera>();
			this.__camera.GetComponent<Light>().range = 200;
			this.__camera.backgroundColor = Color.blue;
			this.__camera.transform.position = this.__selectedTile.transform.position;
			this.__camera.transform.position += (Vector3.up) * 100;
	private void OnDestroy() {
	private void OnLostFocus() {
		if (this.__camera != null) {
			this.__camera = null;
	private void OnGUI() {
		if (this.__camera != null) {	
			Handles.DrawCamera(new Rect(0, 0, this.position.width, this.position.height), this.__camera);
			Handles.PositionHandle(this.__selectedTile.transform.position, Quaternion.identity);
				Gizmos.DrawCube(Vector3.zero, Vector3.one);
				GUI.enabled = this.__selectedTile.forwardTwist == 0;
				EditorGUILayout.LabelField("Skew", EditorStyles.miniBoldLabel);
				this.__selectedTile.skew = EditorGUILayout.IntSlider(this.__selectedTile.skew, -90, 90, GUILayout.Width(TileEditor.__sideBarWidth));
				GUI.enabled = this.__selectedTile.skew == 0;
				EditorGUILayout.LabelField("Twist", EditorStyles.miniBoldLabel);
				this.__selectedTile.forwardTwist = EditorGUILayout.IntSlider(this.__selectedTile.forwardTwist, -90, 90, GUILayout.Width(TileEditor.__sideBarWidth));
				GUI.enabled = true;
	private static void RenderSectionGizmo(Section section, GizmoType gizmoType) {

So both the Gizmo and the Handle (PositionHandle) are not being drawn. What could be going on? The GUI on the other hand IS drawn. Also the DrawGizmo attribute does not work, yet it shows everytime the objects it SHOULD draw (checked it by Debug.Logging the name of the objects shown).


You should call Handles.SetCamera every OnGUI vefore you call DrawCamera. The Handles class is used by all SceneViews, so calling SetCamera once won’t help much.

Oohh interesting! For those of you reading, the handles are actually drawn in the Editor window, using Vector2s! Using HandleUtility you can convert these (through a rather complicated chain of methods) to World coordinates. This applies only to Handles though, not to Gizmos, that still does not work, but I guess it would make sense that you would just add these manually based on GUI coordinates.