-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Saving custom resources using the ResourceSaver.FLAG_BUNDLE_RESOURCES flag causes crash on load. #65393
Comments
The mrp continues to show an error on Godot 4.0 Beta 1 dev (22a09fef5) |
Please re-test in the latest master or a recent beta. PR #71142 has likely fixed this issue. |
Saving a resource with an Got: Dunno if that's the correct way to save nested resources, but that's the error I run into. |
I created a little playground project. |
the problem pops up when |
I'm somewhat curious whether this is technically a bug or not. It's been established it seems that the issue is that FLAG_BUNDLE_RESOURCES is bundling an embedded copy of the NodeData script, which is subsequently creating a naming conflict with the existing NodeData script. It's somewhat nuanced, a script is technically a resource, and it is technically bundling it, along with an error due to the fact the conflicting class_names are not allowed. I think this issue might be difficult to establish a quick fix for and should possibly be punted to allow for broader discussion of what is considered correct behaviour here (should the bundled resource flag simply not bundle scripts with class_name definitions, should this apply to all scripts, ect.?) |
Based on the usage of the save function, i would expect that the resource's data and class name is saved in the save file, and upon load, the engine would look for a class with the same name in the class registry then create an instance of that class to hold the data saved in the file. I wouldn't expect it to save an entire script and load it like it was a new class. i don't actually see the usefulness of that. |
The problem is that Godot 4.x GDScript favours a lot the use of |
Ah, I was hoping this would be fixed by |
Has there been any more discussion about this? I am getting the same error |
still having this issue. Anyone figure out a workaround? Creating the subresources at runtime seems to work if you exclude the ResourceSaver.FLAG_BUNDLE_RESOURCES flag but it's a pain to do that. |
I thought of a way to mitigate the problem while it's still present in the engine. It works by changing bundled scripts with a class name to simply extending the class_name instead. Perhaps it helps one or the other. |
It seems saving resources is still completely broken? I've been searching online and I've found many people with this issue with no solution. I am confused because saving resources should be something pretty much everyone does, how can it be not working? Is this way of saving just wrong? |
I am trying to use this, together with: #74918 (comment) It does not work unfortunately:
Has anyone managed to save and load resources that contain an Array of another resources? |
@Saadies |
There are multiple issues regarding Resources so it get's a bit confusing. I am not using the "BaseResource" class for my resources to fix the saving but for actually duplicating resources at runtime to create new entities in my game. The nested ressources do not get duplicated automatically but stay a reference otherwise. Edit: Okay so, replacing the whole script just with "extends class" is actually the desired behaviour, I understand now. Edit 2: I tried to save a PackedScene that I didn't even use. Everything looks okay now but I still cannot load the file, with a few less errors now:
Edit 3: I removed the custom ResourceBase class from my Resources (from the other script) and I still get the same errors, so It doesn't seem to have any influence on this saving fix. IGNORE BELOW: You are right that something is messed, I can see inside the save file that the scripts are completely replace by just "extends ClassName". I cannot find out why though. When I check the variable "skipped_lines", it contains the whole script and "store_line(skipped)" is called for all lines but the save file is still missing the lines after saving. My resources start like this: class_name DungeonStats
extends ResourceBase
@export var mobLimit : int |
I just understood. I do not know what we are all doing wrong in our actual games for this not to work but this is not the problem. EDIT: The problem comes up when your subresources are instances, then it does not work anymore. |
The problem is when the subresource exists in the project files, just a reference to that resource is saved, even if you duplicate the resource holding the subresource. So if you changed the value of those like say an that won't work. It can be avoided by duplicating them before putting them in the array, or going through the arrays and manually changing them to a duplicate, which is good as long as you are aware of it... or the flag to bundle resources can be used. And that has the problem with the class_names, hence my workaround (even if there are some errors for some cases in it apparently). Another issue is loading savegames, where there's a possibility for arbitrary code execution upon load() if those have scripts, so I end up only using scripts with class name for resources I intend to load from the user:// directory and turn all scripts to a single line to extends ClassName or extends Resource. |
why not have it to where you have one for and one for not, like use a true false statement? or perhaps give the option to change the name the class_name of the bundled script actually after some thought maybe have it to where false doesn't bundle with resource name but true lets you give it a new one Ex. ResourceSaver.save(self, get_filename(), ResourceSaver.FLAG_BUNDLE_RESOURCES, true, new_class_name) not entirely sure how it works on the engine side, just came across this when trying to find a shortcut to saving resources |
Godot version
4.0 dev (106b680) 4.0 dev (432b25d)
System information
windows 10
Issue description
it appears loading a custom resource using
ResourceLoader.load()
on a file saved with theResourceSaver.FLAG_BUNDLE_RESOURCES
can result in a failure to load the file and an error "<custom_class> hides a global script class."Steps to reproduce
create a custom Resource, save it with the
ResourceSaver.FLAG_BUNDLE_RESOURCES
flag, then useResourceSaver.load()
Minimal reproduction project
Minimal reproducable project.zip
The text was updated successfully, but these errors were encountered: