godotengine / godotengine/godot
Changing the script inheritance of a Resource does not update the type in resources and scenes where it is saved as a subresource automatically
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
Tested versions
v4.4.dev5.official [9e6098432]
System information
Godot v4.4.dev5 - Fedora Linux 41 (KDE Plasma) on Wayland - X11 display driver, Multi-window, 1 monitor - Vulkan (Forward+) - integrated Intel(R) UHD Graphics 620 (KBL GT2) - Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz (8 threads)
Issue description
I use custom Resources in my project that inherit from Resource. I decided to change one of them to inherit from BoxShape3D, instead. However, when I saved the script and opened a scene that had it as a subresource, it printed in the console: Script inherits from native type 'BoxShape3D', so it can't be assigned to an object of type 'Resource'. and the resources no longer had script variables saved. When I saved the scene, the script variables were also no longer serialized.
I realized the issue was that it was still saved as "Resource" in the "type" parameter of the PackedScene/Resources where it was saved, but it should actually be "BoxShape3D" since the native type was changed. But for some reason, the editor did not update this automatically as would be expected. I had to manually update every resource's type to "BoxShape3D" using a text editor. This issue doesn't occur where it is saved as a main resource since there is no "type" parameter.
The issue also happens with Nodes, but at least you can change the type directly in the Scene Dock to the right value. But you can't do that with Resources without having to create a new version of it from the Godot editor.
Steps to reproduce
Make a script that inherits from Resource. Optionally add some export variables. Then make a scene and add a Node, and add a script. Add an export variable for the resource. Then in the inspector, add a new resource of that script and set the variables to non-defaults. Then change the base class of the custom resource to something that inherits from Resource. When you run the project, an error should show when running saying Script inherits from native type '*', so it can't be assigned to an object of type 'Resource'.
Minimal reproduction project (MRP)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached resourceissue.zip minimal reproduction project and follow the listed steps to reproduce the inheritance change and serialization error. Inspect how the PackedScene or resource stores the subresource type; done means changing the native base class updates saved subresources so their variables remain serialized without a type-mismatch error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- godot
- Domain
- game-dev, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100