Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion editor/animation/animation_player_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,25 @@ void AnimationPlayerEditor::_animation_selected(int p_which) {
String current = _get_current();

if (!current.is_empty()) {
player->set_assigned_animation(current);
String previous = player->get_assigned_animation();
// Only record an undo step for an actual user re-selection.
// - Skip when nothing changed.
// - Skip when there was no previously assigned animation: set_assigned_animation("")
// is rejected by AnimationPlayer (ERR_FAIL_COND on animation_set.has("")), so there is
// no way to undo back to the "unassigned" state; recording it would create a dead
// undo entry that silently does nothing when triggered (e.g. from _update_player()
// auto-selecting the first animation on a fresh player).
if (previous != current && !previous.is_empty()) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Change Animation"), UndoRedo::MERGE_DISABLE);
undo_redo->add_do_method(player, "set_assigned_animation", current);
undo_redo->add_do_method(player, "stop", false);
undo_redo->add_undo_method(player, "set_assigned_animation", previous);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
undo_redo->add_undo_method(player, "stop", false);
undo_redo->commit_action();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
} else {
player->set_assigned_animation(current);
}

Ref<Animation> anim = player->get_animation(current);
ERR_FAIL_COND(anim.is_null());
Expand Down
15 changes: 14 additions & 1 deletion editor/scene/sprite_frames_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,21 @@ void SpriteFramesEditor::_animation_selected() {
edited_anim = selected->get_text(0);

if (animated_sprite) {
String previous = animated_sprite->call("get_animation");
sprite_node_updating = true;
animated_sprite->call("set_animation", edited_anim);
// Only record an undo step for an actual change with a valid previous animation to
// restore to. AnimatedSprite2D/3D::set_animation() rejects names not present in
// `frames` (ERR_FAIL_MSG), so if `previous` is empty or no longer valid there is no
// way to undo back to it; just apply the change directly in that case.
if (previous != edited_anim && !previous.is_empty() && frames.is_valid() && frames->has_animation(previous)) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Change Animation"), UndoRedo::MERGE_DISABLE, animated_sprite);
undo_redo->add_do_method(animated_sprite, "set_animation", edited_anim);
undo_redo->add_undo_method(animated_sprite, "set_animation", previous);
undo_redo->commit_action();
} else {
animated_sprite->call("set_animation", edited_anim);
}
sprite_node_updating = false;
}

Expand Down
Loading