HxGodot / hxgodot

A Haxe GDExtension for Godot 4
MIT License
232 stars 11 forks source link

Godot Crashes when exporting NodePaths #47

Closed drflamemontgomery closed 1 year ago

drflamemontgomery commented 1 year ago

I've noticed that if you try to export a NodePath it will throw an error when opening the Godot project in Godot.

I have my example code below

package;

class TestClass extends godot.Node {

  // When the line below is removed, Godot doesn't crash
  @:export public var test_export(default, default) : godot.variant.NodePath;

  public function new() {
    super();
  }

}

When I open the project in Godot I get the message

terminate called after throwing an instance of 'Dynamic
drflamemontgomery commented 1 year ago

Just figured out that I have to initialize the NodePath by using 'new NodePath()'

for anyone else who is having trouble, this is the fixed code

package;

class TestClass extends godot.Node {

  @:export public var test_export(default, default) : godot.variant.NodePath = new godot.variant.NodePath();

  public function new() {
    super();
  }

}
dazKind commented 1 year ago

Yes, that's a requirement, otherwise your property is null. You either do it like you did or you do it in the constructor of your class (if you have one)