Saving a nested resource with FLAG_BUNDLE_RESOURCES throws global script error

Godot Version

4.2

Question

I’m unsure whether this is a bug or my error.

I have two custom Resources defined, where one custom Resource holds instances of the other custom Resource:

scripts/parent_resource.gd:

class_name ParentResource
extends Resource

@export var resource_children: Array[ChildResource]

scripts/child_resource.gd

class_name ChildResource
extends Resource

@export var child_name: String

Finally, I have a @tool script attached to a Node that I used to create an instance of ParentResource and save it with ResourceSaver.save. I am using the ResourceSaver.FLAG_BUNDLE_RESOURCES flag to bundle the ChildResource into the ParentResource.

This causes the editor throw an error:
res://test_resource.tres::GDScript_i078r:1 - Parse Error: Class “ChildResource” hides a global script class.

This seems to be because the bundled ChildResource class definition conflicts with the ChildResource definition in scripts/child_resource.gd.

Is this a bug or intended behavior?

I’ve been working with resources for a bit and can tell you that things are a bit shaky under the hood still. It might be any number of things, hard to say.

If you save without the FLAG_BUNDLE_RESOURCES, what happens?

In the minimal example I’ve created here, everything seems fine if I don’t use FLAG_BUNDLE_RESOURCES. :thinking:

However, in my game (which has a more complex set of sub-Resources), I tend to see errors when attempting to assign the sub-Resources to typed variables.

Based on this minimal project, I’ll try to get things working without FLAG_BUNDLE_RESOURCES. Thanks!

2 Likes

I am also having trouble with this. In my case the parent resource has an array which holds resources which have arrays which also have resources…
so creating a system that works around it without using the bundle resource flag is gonna be a THING. Has there been any progress on fixing this issue, or any official advice?