I am encountering an issue with Exporting Custom Resources in C# from a Tool Script.
For example, I have a custom Resource type "TheResource" that I want to export.
[Export(PropertyHint.ResourceType,"TheResource")]
public TheResource MyResource
{
get { return _myResource; }
set { _myResource = value; }
}
private TheResource _myResource = new TheResource();
It does export, however if I clear the Exported Resource and add a new TheResource from the editor, it gives me an error.
/root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs:113 - System.InvalidCastException: Unable to cast object of type 'Godot.Resource' to type 'TheResource'.
So I was thinking, maybe Exported Attributes doesn't support custom Resources (but if it does, then why doesn't it show error like other unsupported data types??), so I tried with the base Resource class, but then I would be forced to cast it into the TheResource class, which is not possible. This just shifts the problem, shifts the error.
[Export(PropertyHint.ResourceType,"TheResource")]
public Resource MyResource
{
get { return _myResource; }
set { _myResource = value as TheResource; }
}
private TheResource _myResource = new TheResource();
Then I was thinking, what if the _myResource ALSO had to be the base Resource class. And, it worked! However, it is now completely useless, as I cannot access the properties within my custom Resource. Again, this shifts the problem because when a resource is created in editor, it is a resource of base class.
[Export(PropertyHint.ResourceType,"TheResource")]
public Resource MyResource
{
get { return _myResource; }
set { _myResource = value; }
}
private Resource _myResource = new TheResource();
private void PrintNumber()
{
GD.Print(_myResource.number); // Error here
}
Please help