public class Block : StaticBody2D
{
private BlockType type {get;}
// private Sprite sprite = new Sprite(); // this line causes a crash
public Block(BlockType type, Vector2 position)
{
this.type = type;
this.Position = position;
// crashes somewhere on the next lines
Sprite sprite = new Sprite();
sprite.Texture = (Texture) GD.Load("res://assets/earth.png");
this.AddChild(sprite);
}
I'm trying to add nodes to a scene via Code. But the code crashes when trying to create objects of some classes like sprites. It also crashes if I want to add another Object as a class-member.
I don't know why the compiler (or godot) crashes on something trivial like Sprite sprite = new Sprite()
How can I do this so I can compile my project?