Previewing procedural drawing code in editor

Godot Version

4.3

Question

When I am writing procedural drawing code (implementing _draw()), I always have the problem how to preview things quickly and easily in the editor while I am writing and tweaking the code.

What I have tried:

  • run the current scene with F6 (Wait a second for the window to open, close the window. A hundred times.)
  • close and re-open the current scene (Ctrl-S, Ctrl-Shift-W, Ctrl-Shift-T)
  • add @tool, and put queue_redraw() in the _process() function: instant updates, but hazardous (danger of slowing down or crashing the editor)

That’s all really clunky. So I was wondering if anyone has a nice workflow when working on procedural drawing code.

Thanks for any input!

Maybe you will find a suitable solution if you search for Hot Reload.

Hot Reload

Hot reloading with VSCode and also debugging with VSCode

Hot reload in Godot (instantly see changes without reloading a game)


There are also some pull requests, it may be improved in the future.
Github PR "reload: "Pull requests · godotengine/godot · GitHub

You could also compile your own Godot Editor if you don’t want to wait long.

I think you want to continue working with a @tool script in the editor… but adding:

if Engine.is_editor_hint():
	queue_redraw()

to the end of whatever is processing/generating your drawings should be safer than just putting it in process.

Do you mean, calling queue_redraw() from within _draw(), so it would endlessly trigger redraws? I just tried that, and it seems to have no effect. I guess you can only trigger a redraw from outside _draw().

Even so, how would that be safer than putting it in _process()?

Hm, lots of interesting stuff around that topic, but I couldn’t find anything relating directly to my problem. Thanks for the pointer, anyway!

1 Like

I’m assuming you are taking some sort of input, running a function to transform some data, and your _draw call is then using that data. If the queue redraw goes in the function that transforms the data, then it only redraws when it is getting input that necessitates a redraw. I’m making an assumption about how your project is structured, so I might be completely off base.

Ah, yes, that‘s how it would eventually work when running the game. Right now I am just looking for a way to quickly preview changes to my drawing code in the editor, before adding interaction. But I guess I could add some temporary input handling to trigger a redraw on keypress. That‘s an idea I will try out. Thanks!

Simple idea: add an export bool to your tool script, give it a setter, and trigger the redraw in the setter.

@export var trigger_redraw : bool = false:
	set(value):
		queue_redraw()

That’ll trigger a redraw when you click the boolean in the inspector.

1 Like

That actually was my very first solution :slight_smile: Works fine, but I found it too annoying for quick iteration.