Error loading a resource to an export var in csharp, but not when assigning in the inspector

Godot Version

v4.4.stable.mono.official [4c311cbee]

Question

I have an export variable that loads a dedicated “settings” resource for my class (a saved version of the resource with .tres extension)

// LOADS "DefaultTerrainEdgeSettings.tres" ; script is type TerrainEdgeSettings
    [Export] public TerrainEdgeSettings EdgeSettings = (TerrainEdgeSettings)GD.Load<Resource>("uid://brdnr7varvh7p");

this spits out this error:

  ERROR:  ---> System.InvalidCastException: Unable to cast object of type 'Godot.Resource' to type 'TerrainEdgeSettings'.

however If I leave it unassigned, and use the inspector to assign the resource it works fine. Is this there something about the order things are loading that is breaking this? Is this a bug?

I wanna fix this, so I have the option to load resources inside scripts that aren’t attached to a node (like nesting resources inside resources)


EDIT:

Weirdly I can fix it by just loading it as a Resource and cast it whatever point in the script I need to read it / pass it :person_shrugging:

Since you made an Export variable I guess you want to set your Resource from within the editor?

[Export] 
public TerrainEdgeSettings EdgeSettings;

Then set your Resource to that property in the editor (in the inspector view of your class).
So Godot takes care of loading the Resource for your class.