Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | null_digital |
extends Control
class_name DrawThing
func _draw():
var dest = Vector2(rect_position.x + 100, rect_position.y + 100)
draw_line(rect_position, dest, Color.white, 5.0)
pass
If I attach DrawThing to a Control in the scene, it’ll draw a line. But if I add it via script:
func _ready():
var draw1 = DrawThing.new()
$NodeGrid/Control/Links.add_child(draw1)
draw1.rect_position = Vector2()
pass
It won’t draw anything. What am I missing?
Having DrawThing extend Node2D solves the issue, but I really wanted to make it work with Control.
Have you checked if $NodeGrid/Control/Link is returning what you want?
Saitodepaula | 2019-12-05 12:20
What do you mean returning?
null_digital | 2019-12-05 12:27
type
print($NodeGrid/Control/Links)
to see what the engine returns. My guess was that it could be returning null
.
But it looks you solved it, mark your own answer as the correct one, so other people know this question is solved.
Saitodepaula | 2019-12-05 13:32
_draw
is a feature inherited from CanvasItem
. Both Control
and Node2D
inherit CanvasItem
, so it should have worked with extending a Control
and using new
… this is quite strange, maybe a bug even?
Zylann | 2019-12-05 13:58
Oh, NodeGrid/Control/Links wasn’t null for both cases.
null_digital | 2019-12-05 16:01