Is it correct that assigning a subresource to a field serializes all other subresources?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AdamActual

Hi all,

I have a custom resource type that contains nested arrays of other custom resource types.

If I assign the root resource to an exported variable in the inspector, it’s serialized in the scene as expected:

[ext_resource type="Script" path="res://custom_2d.gd" id="1_yyxj2"]
[ext_resource type="Resource" uid="uid://ciwcu5po77tou" path="res://test/character-test.myex" id="2_g7hwb"]

[node name="Custom2D" type="Sprite2D" parent="."]
script = ExtResource("1_yyxj2")
_my_resource = ExtResource("2_g7hwb")

However if I drag a subresource of that resource to a different exported variable, it appears to serialize every single subresource of the root resource in the scene itself, including every single variable of those subresources.

Basically along with the above code, I have an entry for every single script class in the children (not just the assigned one), and a sub_resource entry for every single subresource in the resource (including children of children of the assigned subresource).

Is this expected behaviour, not only that it serializes all subresources, but also that it serializes all variable values of all subresources?

Thanks very much!

:bust_in_silhouette: Reply From: zhyrin

It is the expected behaviour, resources serialize recursively.

Although I would note that saying it serializes every variable is probably misleading. It searializes every exported variable.

Thanks for the answer! So just to clarify, why is it serializing recursively in a scene if it’s already serialized in the file system? Should it instead just serialise the reference like it does if I solely assign the root Resource?

AdamActual | 2023-03-23 09:41