Line2D instances created at runtime

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Yigit Gursoy

If I create a Line2D node at run-time, it doesn’t work. However, if I create it as a node in a scene, it works. Could this be a bug or am I missing something?

public override void _Input(InputEvent @event)

    if (@event.IsPressed() 
    && @event is InputEventMouseButton eventMouseButton 
    && eventMouseButton.ButtonIndex == 1)
        var trailScene = ResourceLoader.Load<PackedScene>("res://Scenes/Trail.tscn");
        var trail = (Line2D)trailScene.Instance();
        trail.Points = new Vector2[] { new Vector2(468.958f, 380.869f), new Vector2(309, 209) };
:bust_in_silhouette: Reply From: kidscancode

You’re creating an instance of your scene, but it doesn’t look like you’re adding it to the tree. You need to use addChild() after creating the instance.