0 votes

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) };
      ...
      ...
asked Jan 3 in Engine by Yigit Gursoy (15 points)

1 Answer

+1 vote
Best answer

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.

answered Jan 3 by kidscancode (13,384 points)
selected Jan 3 by Yigit Gursoy
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.