Issue with DrawRect method in EditorGUI

Hello,
I am trying to write an extension that would allow the user to create text/GUI elements and link them together in a form of a tree-like graph. The goal is to allow the user to create custom dialogue chains in a visual environment.

The idea is that a player is supposed to click anywhere on a given window and a rectangle will be drawn on that position.

The problem is that when I call EditorGUI.DrawRect (j, c); , it works, but the moment I do this :

	if (EventType.MouseDown == Event.current.type) {
		...
		EditorGUI.DrawRect (j, c);
	}

It stops working completely (to nothing is being drawn). Why is “EventType.MouseDown == Event.current.type” causing it to fail ?

Note: if the “if” condition is different (for example true), it still works.

Please keep in mind that I am very new to writing editor extensions, so sorry if this is a dumb question.
Thanks!

p.s. If you have any suggestion on how to approach this in a better way (I mean visual editor), I am all ears as I am very new to this.

You may want to read through my IMGUI crash course.

The reason is that you are using the immediate mode GUI system. The immediate mode requires to “manually” redraw every control every frame. For this purpose Unity invokes OnGUI every frame with the Repaint event. Each “control method” internally checks the current event type. The controls only draw themselfs during the repaint event. Since you only call “EditorGUI.DrawRect” when a MouseDown event happens, nothing happens at all. DrawRect doesn’t react to any input events like MouseDown.