0 votes

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

in Engine by (27,778 points)

3 Answers

0 votes

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.

by (679 points)

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

+1 vote

You have a function on CanvasItem to set the base trasform of all the following draw commands:

void draw_set_transform ( Vector2 pos, float rot, Vector2 scale )


You can reset it to pos=Vector2(), rot=0, scale=Vector2(1,1) and will be drawing in global coordinates.

by (16 points)

I tried this already, but it doesn't works. It adds the transformation, not replace it.

Then set the inverse trasform of your node with the getglobaltransform().inverse() and using the pos,rot,scale of that matrix.

0 votes

I created an issue in which we discussed on the ways of doing it for a custom particle system https://github.com/godotengine/godot/issues/5428

by (27,778 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.