### Godot version

4.1b

### System information

win11 Vulkan API 1.3.236

### Issue description

Selecting AnimationTree will result in error message 
`This function in this node can only be accessed from either the main thread or a thread group. Use call_deferred() instead.`

### Steps to reproduce

AnimationTree -> ROOT -> AnimationNodeStateMachine ->Add Animation.
There are several animations, clicking AnimationTree will result in several errors

### Minimal reproduction project

[test.zip](https://github.com/godotengine/godot/files/11708080/test.zip)

button_path.clear();
	Ref<AnimationNode> node = tree->get_tree_root();
	if (node.is_valid()) {
		current_root = node->get_instance_id();
		for (int i = 0; i < p_path.size(); i++) {
			Ref<AnimationNode> child = node->get_child_by_name(p_path[i]);
			ERR_BREAK(child.is_null());
			node = child;
			button_path.push_back(p_path[i]);
		}
		edited_path = button_path;