Repository: godot
Issue: Saving and restoring AnimationNodeStateMachine works unreliably/unpredictably
Labels: bug,topic:editor,topic:animation

### Godot version

4.2.beta3

### System information

Godot v4.2.beta3 - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4090 (NVIDIA; 31.0.15.3598) - 13th Gen Intel(R) Core(TM) i9-13900K (32 Threads)

### Issue description

I have an `AnimationTree` with several sub-`AnimationNodeStateMachine`s. I have made edits to the AnimationNodeStateMachines and used the "Save" popup menu on the node to try and save the state machine out as a resource.

Sometimes it works. Sometimes it does nothing and I see errors in the console. Attempting to save a node as "block_playback.tres" produces errors in the debugger and errors in the output.

Some examples of the errors:
```
E 2:20:57:0103   set_node_position: Condition "!nodes.has(p_node)" is true.
  <C++ Source>   scene/animation/animation_blend_tree.cpp:1233 @ set_node_position()
```

Some examples of the output pane errors:
```
  EditorProperty is outside inspector.
  EditorProperty is outside inspector.
  EditorProperty is outside inspector.
  EditorProperty is outside inspector.
  Another resource is loaded from path 'res://weapons/block_playback.tres' (possible cyclic resource inclusion).
```

Some notes:
1. The save operation appears to work on the first save and shows the object on the StateMachine node as the saved tres.
2. When the scene is reloaded the AnimationNodeStateMachine no longer points to the resource, and instead points to an internally generated one.
3. If I try and update this same AnimationNodeStateMachine and save it out again it will not update to match the resource.


### Steps to reproduce

# Steps to Reproduce:
1. Create a new scene
2. Add an `AnimationTree` and open the AnimationTree editor
3. Add a single StateMachine to the canvas.
4. Open Editor for the new StateMachine and add a single node to it so that it has been edited.
5. Close the StateMachine editor and click on the popup menu for saving the resource out.  <img width="146" alt="image" src="https://github.com/godotengine/godot/assets/742517/9f0341e2-c3c5-489c-b6e6-3bbc3ae481ce">
6. Save out the resource and give it a name.  <img width="302" alt="image" src="https://github.com/godotengine/godot/assets/742517/90ac4012-be99-47c6-8e08-890081bccfc8">
7. Notice the name of the resource has update on the node. <img width="120" alt="image" src="https://github.com/godotengine/godot/assets/742517/40e3d3b8-ae64-4ff6-8b09-ba5429523556">
8. Save the AnimationTree scene you created in step 1.
9. Close the scene.
10. Open the scene, and switch to the AnimationTree editor.

# Results:
- The node you previously created no longer references the saved resource.

## Further unexpected behavior:
1. Try and update the resource on the node by choosing "Quick Load" and referencing the file you previously saved.
2. Notice the resource does not update.

## Further unexpected behavior:
1. Try and update the resource on the node by choosing "Quick Load" and referencing a different `AnimationNodeStateMachine` resource.
2. Open the StateMachine editor.
3. Notice that the StateMachine still has the old configuration. The load failed.


# Expectations:

The saving and restoring of StateMachine resources doesn't appear to work for existing StateMachines. The workaround for the current behavior is to delete the old state machine, create a new one, load the config from disk, and then continue. This workaround is hard to discover, as the Save/Open commands only appear to work for the first edit. They fail on subsequent edits.


### Minimal reproduction project

N/A