Topic was automatically imported from the old Question2Answer platform.
Asked By
Zylann
Old Version
Published before Godot 3 was released.
I need to draw debug lines and circles in _draw() to verify if an enemy AI script is working.
However, I want those drawings to be independent from the node’s transform.
I tried to call debug_set_transform() but it doesn’t resets the current transform, instead it adds another one on top.
I tried to create another node to use as a global debug drawer but I get this error:
ERROR: Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.
At: scene\2d\canvas_item.cpp:706
From the enemy script send a signal that is caught by a node that is globally positioned. Then draw normally on that node.
Anyway, drawing over the enemy node (even with its own transformation) is not a bad idea because this way you know that the actual script of that enemy node is working and not other.
I would prefer not to rely on another node because it’s too awkward to setup for a debug system. Also, I tried to use a different node for drawing so instead I write something like:
func _draw():
var debug_node = get_debug_node()
debug_node.draw_line(...)
But as I said, it creates an error and doesn’t draws anything for some reason…
I prefer drawing directly from the concerned node, but it’s a spinning RigidBody and it’s awful to draw aligned things from it :s