So far what I have been building has been working fine. But I have no idea where this error is coming from and I don't want it to brick anything later down the line.
I'm planning on using Panel segments as parts of the snake, I haven't gotten to movement or much else yet.
Thanks for all the help
Code
public partial class Main : Node
{
[Export]
public PackedScene SnakeScene { get; set; }
private List<Panel> Snake = new List<Panel>();
public override void _Ready()
{
AddSegment(new Vector2(200, 200));
GenerateSnake();
foreach (Panel item in Snake)
{
GD.Print(this.ToString());
}
}
public void AddSegment(Vector2 pos)
{
Panel test = (Panel)SnakeScene.Instantiate();
test.Position = pos;
Snake.Add(test);
AddChild(test);
}
public void GenerateSnake()
{
for (int i = 0; i < 3; i++)
{
AddSegment(new Vector2(450,450+i*50));
}
}
}```
Error
E 0:00:00:813 void Main.AddSegment(Godot.Vector2): System.NullReferenceException: Object reference not set to an instance of an object.
<C# Error> System.NullReferenceException
<C# Source> Main.cs:37 @ void Main.AddSegment(Godot.Vector2)
<Stack Trace> Main.cs:37 @ void Main.AddSegment(Godot.Vector2)
Main.cs:19 @ void Main._Ready()