Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling AnimationPlayer.RootNode from C# errors in exported version #82993

Closed
poohcom1 opened this issue Oct 8, 2023 · 1 comment · Fixed by #83440
Closed

Calling AnimationPlayer.RootNode from C# errors in exported version #82993

poohcom1 opened this issue Oct 8, 2023 · 1 comment · Fixed by #83440

Comments

@poohcom1
Copy link
Contributor

poohcom1 commented Oct 8, 2023

Godot version

4.2-dev6

System information

Windows 11

Issue description

Using the RootNode getter on AnimationPlayer from C# causes the following error in both debug and release exports.

ERROR: System.TypeInitializationException: The type initializer for 'Godot.AnimationMixer' threw an exception.
 ---> Godot.GodotObject+NativeMethodBindNotFoundException: Unable to find the native method bind. (Method 'AnimationMix)
   at Godot.GodotObject.ClassDB_get_method_with_compatibility(StringName type, StringName method, UInt64 hash)
   at Godot.AnimationMixer..cctor()
   --- End of inner exception stack trace ---
   at Godot.AnimationMixer.GetRootNode()
   at Godot.AnimationMixer.get_RootNode()
   at TestCSharp._Ready() in C:\Users\Pooh\Code\games\test-4.2dev6-animplayer\TestCSharp.cs:line 11
   at Godot.Node.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret)
   at Godot.CanvasItem.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret)
   at Godot.Node2D.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret)
   at TestCSharp.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret) in C:8
   at Godot.Bridge.CSharpInstanceBridge.Call(IntPtr godotObjectGCHandle, godot_string_name* method, godot_variant** arg)
   at: void Godot.NativeInterop.ExceptionUtils.LogException(System.Exception) (:0)

The code runs fine in the editor and the same issue does not happen with GDScript.

Steps to reproduce

From scratch:

  1. Create a C# script that references an AnimationPlayer.
  2. Call AnimationPlayer.RootNode.
  3. Create a debug or release export.
  4. Run the export with console.
  5. The scene will show a "GDScript" label, but not the "CSharp" label because the CSharp script errored.
  6. Check the console output for the error message.

With the MRP:

  1. Create an export.
  2. Run the export with console.
  3. Same steps as above.

Minimal reproduction project

dotnet-getrootnode-mrp.zip

@raulsntos
Copy link
Member

raulsntos commented Oct 8, 2023

It seems #80813 introduced methods that are only bound when running in/from the editor:

#ifdef TOOLS_ENABLED
ClassDB::bind_method(D_METHOD("_reset"), &AnimationMixer::reset);
ClassDB::bind_method(D_METHOD("_restore", "backup"), &AnimationMixer::restore);
ClassDB::bind_method(D_METHOD("set_reset_on_save_enabled", "enabled"), &AnimationMixer::set_reset_on_save_enabled);
ClassDB::bind_method(D_METHOD("is_reset_on_save_enabled"), &AnimationMixer::is_reset_on_save_enabled);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "reset_on_save", PROPERTY_HINT_NONE, ""), "set_reset_on_save_enabled", "is_reset_on_save_enabled");
ADD_SIGNAL(MethodInfo("mixer_updated")); // For updating dummy player.
#endif // TOOLS_ENABLED

I think this is the same as #72864. This was fixed by moving the #ifdef DEBUG_ENABLED to the methods implementation (#72922) so maybe we should do something similar here.

cc @TokageItLab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants