Repository: godot
Issue: Resource Serialization Problem in Editor
Labels: topic:core,topic:editor,needs testing

### Tested versions

Only noticed it since v4.3.dev.custom_build [1c8ae43ef]

### System information

Godot v4.3.dev (1c8ae43ef) - Ubuntu 22.04.3 LTS 22.04 - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2060 (nvidia; 535.154.05) - Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz (6 Threads)

### UPDATED

I have narrowed this down to a much simpler demo of the issue. I will push the OP down and insert my new info at the top.

### Issue description

I have found a situation where resources that are changed in code (gdscript) do not get saved when Ctrl+S is used in the editor. The best I can say is that *when there is an Array involved* bad things happen.

(Changing a resource *in the inspector*, then ctrl + S always saves fine. Saving from the inspector icons also works.)

### Steps to reproduce

1. Fetch the MRP. Open main. See Inspector for the only node.
2. Press : Loadres (once) (creates it if it's not there)
3. (Now open thing.tres in an external editor so you can watch it)
4. Press : Change Array Only, Ctrl+s == it saves ONLY the first time
5. Press : Change Array Only, Ctrl+s == it does NOT save again
6. Press : Change All, Ctrl+s == it saves EVERY TIME

∴ Something about arrays in resources is wonky. It may be related to https://github.com/godotengine/godot/issues/59669 - not sure.

No regression, per say, could be found. Same happens on:
.Godot_v4.2-stable_linux.x86_64
.Godot_v4.2-rc1_linux.x86_64
.Godot_v4.2.1-stable_linux.x86_64
.Godot_v4.2.1-rc1_linux.x86_64
.Godot_v4.1.1-stable_linux.x86_64

### Very boring output to show issue

You can see when data AND name change, then ctrl+s saves, but if "Change Array Only" is pressed, it doesn't save (after the first time)

```
CREATE
LOAD
thing name:Name0
thing data:[1]
^Z
$ cat thing.tres
[gd_resource type="Resource" script_class="Thing" load_steps=2 format=3 uid="uid://cf80e3igckkne"]
[ext_resource type="Script" path="res://thing.gd" id="1_g34hl"]
[resource]
script = ExtResource("1_g34hl")
data = Array[int]([1])
name = "Name0"
$ fg

CHANGE <-- first press of Change Array Only
thing data changed to:[1, 2] (I press ctrl+S here)
^Z
$ cat thing.tres
[gd_resource type="Resource" script_class="Thing" load_steps=2 format=3 uid="uid://chor4rj0lgott"]
[ext_resource type="Script" path="res://thing.gd" id="1_g34hl"]
[resource]
script = ExtResource("1_g34hl")
data = Array[int]([1, 2])
name = "Name0"
$ fg

CHANGE <-- Second press of Change Array Only
thing data changed to:[1, 2, 3] (I press ctrl+S here)
^Z
$ cat thing.tres
[gd_resource type="Resource" script_class="Thing" load_steps=2 format=3 uid="uid://chor4rj0lgott"]
[ext_resource type="Script" path="res://thing.gd" id="1_g34hl"]
[resource]
script = ExtResource("1_g34hl")
data = Array[int]([1, 2])  <-- the array is wrong
name = "Name0"

$ fg
CHANGE <-- Chnage All was pressed
thing name changed to:Name3
thing data changed to:[1, 2, 3, 4] (I press ctrl+S here)
^Z
$ cat thing.tres
[gd_resource type="Resource" script_class="Thing" load_steps=2 format=3 uid="uid://chor4rj0lgott"]
[ext_resource type="Script" path="res://thing.gd" id="1_g34hl"]
[resource]
script = ExtResource("1_g34hl")
data = Array[int]([1, 2, 3, 4]) <-- The array has updated
name = "Name3"

$ fg
CHANGE <-- I do more tests
thing data changed to:[1, 2, 3, 4, 5] (I press ctrl+S here)
CHANGE
thing data changed to:[1, 2, 3, 4, 5, 6] (I press ctrl+S here)
^Z
$ cat thing.tres
[gd_resource type="Resource" script_class="Thing" load_steps=2 format=3 uid="uid://chor4rj0lgott"]
[ext_resource type="Script" path="res://thing.gd" id="1_g34hl"]
[resource]
script = ExtResource("1_g34hl")
data = Array[int]([1, 2, 3, 4])
name = "Name3"

$ fg
CHANGE
thing name changed to:Name6
thing data changed to:[1, 2, 3, 4, 5, 6, 7] (I press ctrl+S here)
^Z
$ cat thing.tres
[gd_resource type="Resource" script_class="Thing" load_steps=2 format=3 uid="uid://chor4rj0lgott"]
[ext_resource type="Script" path="res://thing.gd" id="1_g34hl"]
[resource]
script = ExtResource("1_g34hl")
data = Array[int]([1, 2, 3, 4, 5, 6, 7])
name = "Name6"
```

### Minimal reproduction project (MRP)
A small repo here: https://gitlab.com/dbat/resource_editor_issue


---


### Older Issue description

In a `@tool`, saving* a resource (A) which holds a reference to another resource (B) does not save B.

*Saving means ResourceSaver.save() as well as Ctrl+S in the editor. Ctrl+S behaves strangely. It depends what is in focus when you invoke it. More info in the comments of the code below.

### Steps to reproduce

<snipped> Older code is in MRP too.