Failed Loading of Custom Resource

Godot Version

v4.5.1.stable.steam [f62fdbde1]

Question

In the game/project I’ve been working on, a savable player has Arrays of custom classes that extend from the Resource class. These are namely the ‘Dragon’ class, which saves and loads just fine, and the ‘Clutch’ class, which saves without any error message provided but fails to load with the following information:

Everything else that the player has loads just fine and without issue, using the following code: (save location is temporary during the making of the game, code was made with the help of this YouTube tutorial that was recommended on the official Godot docs)

I don’t know if it matters, but the constructor for a Clutch looks like so:

If anyone has any idea why the Clutch class doesn’t load and/or tips on what to try for fixing it, I’m all ears.

Can you send the code for the resource you are trying to load?

By overriding the constructor with a mandatory argument, you prevented the engine to do the default object construction i.e. calling the constructor without arguments (when doing duplication or creating a fresh object under the hood)

When implementing your own constructors with arguments, always provide default values for all arguments so the engine can make that default call, without supplying any.

From Object::_init() reference in the docs:

Note: If _init() is defined with required parameters, the Object with script may only be created directly. If any other means (such as PackedScene.instantiate() or Node.duplicate()) are used, the script’s initialization will fail.

1 Like

The suggestion I was given shortly after you asked for the code worked to fix it, but I’ll offer you the full current (and fixed) code here:


1 Like

Alright, thats good

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.