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

CSharp Tool scripts cannot have custom resource properties set in the inspector #85825

Closed
Mantissa-23 opened this issue Dec 6, 2023 · 1 comment

Comments

@Mantissa-23
Copy link

Tested versions

  • Reproducible In: 4.2.stable.mono

I suspect but have not confirmed that this bug has always been present in the C# build.

System information

Godot v4.2.stable.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3080 (NVIDIA; 31.0.15.3734) - AMD Ryzen 9 5900X 12-Core Processor (24 Threads)

Issue description

A C# tool script cannot have a custom resource property set. It will result in the following error:

  /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs:112 - System.InvalidCastException: Unable to cast object of type 'Godot.Resource' to type 'Prism.ProceduralAnimation.JointConstraintSet'.
     at Prism.ProceduralAnimation.InverseKinematics.RestoreGodotObjectData(GodotSerializationInfo info) in C:\Users\Dylan\Projects\studio-mantissa\Godot.SourceGenerators\Godot.SourceGenerators.ScriptSerializationGenerator\Prism.ProceduralAnimation.InverseKinematics_ScriptSerialization.generated.cs:line 32
     at Prism.ProceduralAnimation.IKOnNode3D.RestoreGodotObjectData(GodotSerializationInfo info) in C:\Users\Dylan\Projects\studio-mantissa\Godot.SourceGenerators\Godot.SourceGenerators.ScriptSerializationGenerator\Prism.ProceduralAnimation.IKOnNode3D_ScriptSerialization.generated.cs:line 22
     at Godot.Bridge.CSharpInstanceBridge.DeserializeState(IntPtr godotObjectGCHandle, godot_dictionary* propertiesState, godot_dictionary* signalEventsState) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/CSharpInstanceBridge.cs:line 255

Steps to reproduce

Assuming MRP:

  1. Select any node that has a tool script with a custom resource property
  2. Attempt to create a new resource to fill that property, or load a resource from the filesystem
  3. Property will remain null, and resource will not be created, and the above error will be thrown.

Minimal reproduction project (MRP)

CSharp Tool Script Resource Error MRP.zip

@raulsntos
Copy link
Member

raulsntos commented Dec 7, 2023

Scripts not marked as [Tool] can't be instantiated in the editor, instead we create a placeholder to hold the necessary data (that's how you can edit it in the inspector). So you need to add the [Tool] attribute to the C# classes that you want to use in the editor (this includes resources that you want to access from other tool scripts because they run in the editor).

Make sure to read the Running code in the editor documentation page for more information.

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

No branches or pull requests

2 participants