- Home /
Drawing a line in a EditorWIndow?
Hi,
I need to draw a line between two points in an Editor window. I have found this answer but it is not working for me: http://answers.unity3d.com/questions/428599/how-to-make-a-line-between-object-in-editor-window.html
Does Handles.DrawLine just works inside an OnSceneGUI method? I have tried this too without any luck.
I would like to draw a line inside OnGUI if it is possible.
The code:
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
public class NodeWindow : EditorWindow
{
const int kPadding = 10;
List<INode> _nodes = new List<INode>();
INode _currentNode = null;
[MenuItem("ComboMaker/Node window")]
static void Create()
{
// Get existing open window or if none, make a new one:
NodeWindow window = (NodeWindow)EditorWindow.GetWindow(typeof(NodeWindow));
window.Show();
}
public NodeWindow()
{
}
public void OnGUI()
{
Handles.BeginGUI();
Handles.color = Color.red;
Handles.DrawLine(new Vector3(0, 0), new Vector3(300, 300));
Handles.EndGUI();
}
}
Cheers.
Do you call your code after a BeginWindows() and before EndWindows()?
I do this inside OnGUI in the EditWindow:
Handles.BeginGUI();
Handles.color = Color.red;
Handles.DrawLine(new Vector3(0, 0), new Vector3(300, 300));
Handles.EndGUI();
@Graphics_Dev I just added the code I'm using
This seems to work just fine; I commented out lines 9-11 (because INode is created somewhere else). It draws a red line in your node window. You can use a Vector2 on line 30 because you are drawing in 2D space not in the scene view ;)
Answer by hexdump · Feb 23, 2016 at 03:51 PM
Wel, I finally sorted out the problem. Indeed, it was a refresing problem. I must draw every frame the line.
Cheers!
Your answer
![](https://koobas.hobune.stream/wayback/20220612065315im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Custom Editor - Is there any way to detect whether the user is in Prefab editing mode? 1 Answer
Set MinWidth for EditorWindow 1 Answer
mouseposition and clicks in editor sceneview 0 Answers
Editor Window Views 0 Answers
Print to status bar. 0 Answers