### 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)

while (path_hb->get_child_count() > 1) {
		memdelete(path_hb->get_child(1));
	}
	Ref<ButtonGroup> group;
	group.instantiate();
	Button *b = memnew(Button);
	b->set_text(TTR("Root"));
	b->set_toggle_mode(true);
	b->set_button_group(group);
	b->set_pressed(true);
	b->set_focus_mode(FOCUS_NONE);
	b->connect("pressed", callable_mp(this, &AnimationTreeEditor::_path_button_pressed).bind(-1));
	path_hb->add_child(b);
	for (int i = 0; i < button_path.size(); i++) {
		b = memnew(Button);
		b->set_text(button_path[i]);
		b->set_toggle_mode(true);
		b->set_button_group(group);
		path_hb->add_child(b);
		b->set_pressed(true);
		b->set_focus_mode(FOCUS_NONE);
		b->connect("pressed", callable_mp(this, &AnimationTreeEditor::_path_button_pressed).bind(i));
	}
}
void AnimationTreeEditor::edit_path(const Vector<String> &p_path) {