Repository: godotengine/godot
File: editor/animation_track_editor.cpp (C++)

Code before:
				return;
			}

			if (node == AnimationPlayerEditor::get_singleton()->get_player()) {
				EditorNode::get_singleton()->show_warning(TTR("AnimationPlayer can't animate itself, only other players."));
				return;
			}

			EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
			undo_redo->create_action(TTR("Add Track"));
			undo_redo->add_do_method(animation.ptr(), "add_track", adding_track_type);
			undo_redo->add_do_method(animation.ptr(), "track_set_path", animation->get_track_count(), path_to);
			undo_redo->add_undo_method(animation.ptr(), "remove_track", animation->get_track_count());
			undo_redo->commit_action();

		} break;
	}
}

void AnimationTrackEditor::_add_track(int p_type) {
	if (!root) {
		EditorNode::get_singleton()->show_warning(TTR("Not possible to add a new track without a root"));
		return;
	}
	adding_track_type = p_type;
	pick_track->popup_scenetree_dialog();
	pick_track->get_filter_line_edit()->clear();
	pick_track->get_filter_line_edit()->grab_focus();
}

void AnimationTrackEditor::_fetch_value_track_options(const NodePath &p_path, Animation::UpdateMode *r_update_mode, Animation::InterpolationType *r_interpolation_type, bool *r_loop_wrap) {
	AnimationPlayer *player = AnimationPlayerEditor::get_singleton()->get_player();
	if (player->has_animation(SceneStringNames::get_singleton()->RESET)) {
		Ref<Animation> reset_anim = player->get_animation(SceneStringNames::get_singleton()->RESET);
		int rt = reset_anim->find_track(p_path, Animation::TrackType::TYPE_VALUE);
		if (rt >= 0) {
			*r_update_mode = reset_anim->value_track_get_update_mode(rt);
			*r_interpolation_type = reset_anim->track_get_interpolation_type(rt);
			*r_loop_wrap = reset_anim->track_get_interpolation_loop_wrap(rt);
			return;
		}
		rt = reset_anim->find_track(p_path, Animation::TrackType::TYPE_BEZIER);
		if (rt >= 0) {
			*r_interpolation_type = reset_anim->track_get_interpolation_type(rt);
			*r_loop_wrap = reset_anim->track_get_interpolation_loop_wrap(rt);
			return;
		}
	}

	// Hack.
	NodePath np;

Review comment (bug):
Something is wrong with the `root` variable. When you change the `root_node` property, you need to reselect the AnimationPlayer to update it.

Code after:
				return;
			}

			if (node == AnimationPlayerEditor::get_singleton()->get_player()) {
				EditorNode::get_singleton()->show_warning(TTR("AnimationPlayer can't animate itself, only other players."));
				return;
			}

			EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
			undo_redo->create_action(TTR("Add Track"));
			undo_redo->add_do_method(animation.ptr(), "add_track", adding_track_type);
			undo_redo->add_do_method(animation.ptr(), "track_set_path", animation->get_track_count(), path_to);
			undo_redo->add_undo_method(animation.ptr(), "remove_track", animation->get_track_count());
			undo_redo->commit_action();

		} break;
	}
}

void AnimationTrackEditor::_add_track(int p_type) {
	AnimationPlayer *ap = AnimationPlayerEditor::get_singleton()->get_player();
	if (!ap) {
		ERR_FAIL_EDMSG("No AnimationPlayer is currently being edited.");
	}
	Node *root_node = ap->get_node_or_null(ap->get_root_node());
	if (!root_node) {
		EditorNode::get_singleton()->show_warning(TTR("Not possible to add a new track without a root"));
		return;
	}
	adding_track_type = p_type;
	pick_track->popup_scenetree_dialog(nullptr, root_node);
	pick_track->get_filter_line_edit()->clear();
	pick_track->get_filter_line_edit()->grab_focus();
}

void AnimationTrackEditor::_fetch_value_track_options(const NodePath &p_path, Animation::UpdateMode *r_update_mode, Animation::InterpolationType *r_interpolation_type, bool *r_loop_wrap) {
	AnimationPlayer *player = AnimationPlayerEditor::get_singleton()->get_player();
	if (player->has_animation(SceneStringNames::get_singleton()->RESET)) {
		Ref<Animation> reset_anim = player->get_animation(SceneStringNames::get_singleton()->RESET);
		int rt = reset_anim->find_track(p_path, Animation::TrackType::TYPE_VALUE);
		if (rt >= 0) {
			*r_update_mode = reset_anim->value_track_get_update_mode(rt);
			*r_interpolation_type = reset_anim->track_get_interpolation_type(rt);
			*r_loop_wrap = reset_anim->track_get_interpolation_loop_wrap(rt);
			return;
		}
		rt = reset_anim->find_track(p_path, Animation::TrackType::TYPE_BEZIER);
		if (rt >= 0) {
			*r_interpolation_type = reset_anim->track_get_interpolation_type(rt);
			*r_loop_wrap = reset_anim->track_get_interpolation_loop_wrap(rt);
			return;