I can't assign a custom resource in a custom resource on run time

Godot Version

4.6

Question

I have an adventurer custom resource saved as a file.

I am creating custom item resources on run time. (weapons and armor)

When I am assigning the custom item resource into the adventurer exported variable (that accepts that specific custom resource) it doesn’t do anything.

HOWEVER

When I create the adventurer custom resource on runtime as well, it does accept the items.

Am I missing important knowledge or am I doing it wrong?

Yes?

You have not provided enough details (specifically code) to find a solution to your issue.

Just saw this help thread mentioned using const with a resource prevents its variables from being changed. Also when you say it hasn’t changed do you mean on disc or at runtime. If it’s not changing in disc it’s because you need to save it again.

I think that’s what const do.

It doesn’t change on runtime. I was checking the remote scene tree. In the end I am just creating the adventurer custom resource on runtime as well since it seems to be working that way but new problems might arise this way later on.

Any updates on this?

I have the same issue for like months now!

That might not be the problem, but I had issues with loading resources with an “_init(…)” function, so try just removing the function and using a custom static function to initialize your resources

As I said, I am getting around it by creating the adventurer custom resource on runtime instead of referencing it as a save file :expressionless:

This is weird as well this is a design violation. Any method from a parent class `Object` should be valid in all subclasses.

In my case, I was making a generic serialization for Godot classes. The way to do this is by using `set()` and `get()` of `Object` class. Apparently, like overwriting `_init()` in Resource class, using `set()` method on new resource object would make the engine flagging it as a possible cyclic reference error. The unintuitive communications between Resource objects and the resource server would lead to custom development just to store data in a class like `Resource` that has the advantage of being viewed in the editor.

I guess storing data in RefCounted class is more stable than the Resource class although it would not be shown in the editor like resource objects at least not without making an editor plugin.

If you’re just generating your things in realtime and you don’t care about saving/loading them, RefCounted should do the trick, also because by default inner classes (those declared with the ‘class’ keyword) are themselves RefCounteds and they work just fine. If you ever need to save/load them though, you will need to write your own logic, wich shouldn’t be complicated