I modify this post to: would it be correct assuming a platform in general, to create a script(resource) file that contains literally any other type of resource I prefer inside it? Ok I would like to give an example, just to get an opinion from more experienced users. Example: I create a container named “Game” which in turn contains three resource variables of type “level”. Then I make “level” contain a resource of type “enemy” and “trap” etc… ? Thanks
A custom resource is kind of like a blueprint for a structure of data that can have variables and methods inside of them, exactly like a custom class.
For example, for a card game you may have a custom resource for cards. They have a name, a card sprite, some parameters and some helpful methods.
After the creation of the custom resource, you may create resource objects that is built out of the custom resource AKA blueprint. A practical usecase is to create an export variable in your scene of the custom resource type so you can drag and drop your created resource object into it.
Some people also construct a savefile as a custom resource, that’s why it may be possible to have several save files for one game.
Maybe a video would be better at explaining these concepts:
Yes but let’s say I create a resource class “X”, of this class I create as many resource objects as I want so let’s say I create two resource objects for example “X1” and “X2”. Then I create two scenes: the first one called “main” and the second one called “player”. Meanwhile in the scene “player” I export the two objects of type “X” i.e. “X1” and “X2”. I then decide to instantiate “player” twice in the “main” scene. And this is where the first question arises: if I insert “X1” in the first instance and “X2” in the second instance of “player,” does the resource object “X1” make its instance a different object from the second instance in which I inserted the resource object “X2”?
If you instance player twice with each of the resource objects as exports, than both players will use the same resource with shared variables. If you do not want that to be the case, then you should go into the exported Resources and enable local_to_scene or mark the resource as Make Unique, which ensures that every instance of Player will use the variables and methods inside of the custom resource locally and separately.
That’s one of the edge cases where you need to just test it out
A parallel to that is when using shaders, materials and themes. If you change any of these, then the effect is applied to every single object that makes use of these resources. One way to treat the object individually is by use of the aforementioned local_to_scene and Make Unique.