Add toggle for inserting keys/markers at current time vs mouse cursor's position#107511
Conversation
|
Quick question: the toggle is enabled by default, so keys/markers go to the timeline cursor. Happy to change it if needed! |
|
Imo I think this should be an opt in, so disabled by default |
5884407 to
dd88dd7
Compare
|
Just pushed a small update: changed the default to false for compatibility with the previous behavior (inserting at mouse position). |
dd88dd7 to
98ae23a
Compare
TokageItLab
left a comment
There was a problem hiding this comment.
Oh sorry, I overlooked, but we need to use double for the time.
|
Just discovered a bug when insert_at_current_time is enabled, inserting multiple keys quickly results in insertion of multiple keys away from current time. This doesn't happen with markers. insert_bug.mp4Cause: while (animation->track_find_key(p_track, p_ofs, Animation::FIND_MODE_APPROX) != -1) {
p_ofs += SECOND_DECIMAL;
}Fix: while (animation->track_find_key(p_track, p_ofs, Animation::FIND_MODE_APPROX) != -1 && !is_insert_at_current_time_enabled()) {
p_ofs += SECOND_DECIMAL;
}I'll include this fix along with the other changes. Let me know if it looks okay! |
Some operations (such as baking) require keys to be inserted, but I assume this was a hack to prevent the index from being corrupted due to overwriting (deletion). In the case of markers, the current skip operation is okay, but in the case of keys, it will be necessary to test whether there are any problems in some operations. |
What do you think about skipping key insertion at the current time if a key already exists and |
Currently, AnimationPlayer still pastes or duplicates keys at the timeline cursor when using keyboard shortcuts. However, when using the menu, keys are inserted at the mouse position. I tried to make the toggle affect paste/duplicate as well, but both functions currently overwrite existing keys without any checks, which could lead to unintended behavior—as @TokageItLab pointed out. |
|
Existing keys should be always overwritten with the latest pasted/inserted keys. However, in cases where multiple keys are selected and processed sequentially, care must be taken not to break the indices. At this point, we also need to be careful about the Undo operation. I think the fundamental problem is that the same method is used for inserts from both external operation and internal sources. Ideally, it would be great to be able to fix to override always take into account sequence and undo, but that might be a big change to include in this PR. For now, I think you can leave it as the default behavior and then raise an issue saying “keys cannot be inserted in the same position” and fix it in a separate PR. |
|
I tested pasting and duplicating keys at the same position multiple times. They currently overwrite existing keys as expected, and undo/redo works correctly. made the toggle button affect paste and duplicate operations: - emit_signal(SNAME("duplicate_request"), insert_at_pos, true);
+ emit_signal(SNAME("duplicate_request"), insert_at_pos, !editor->is_insert_at_current_time_enabled());
- emit_signal(SNAME("paste_request"), insert_at_pos, true);
+ emit_signal(SNAME("paste_request"), insert_at_pos, !editor->is_insert_at_current_time_enabled());changed the function resolve_insertion_offset() to use reference passing and changed function call accord to it: -float AnimationTrackEditor::get_insert_at_current_time_position_if_enabled(float p_fallback_ofs) const {
+void AnimationTrackEditor::resolve_insertion_offset(float &r_offset) const {
if (is_insert_at_current_time_enabled()) {
- return timeline->get_play_position();
- } else {
- return p_fallback_ofs;
+ r_offset = timeline->get_play_position();
}
}Let me know if this looks good or if anything should be tweaked before I push it. |
|
Since we need to squash them and make a single commit in the end, you can push them casually so that we can build them :) |
|
Everything requested so far has been addressed and pushed — the toggle now affects insert, paste, and duplicate as expected. |
KoBeWi
left a comment
There was a problem hiding this comment.
Looks good.
Still needs animation team review probably.
|
Accidently closed the pr while using mobile client, my bad. |
TokageItLab
left a comment
There was a problem hiding this comment.
Tested and LGTM, please squash commits into one to follow our PR workflow.
|
squashed all the commits to a single commit :) |
|
CI test seems to be malfunctioning, so we will run the gitHub action job again later. I think the code is fine now, thanks. |
|
Ran |
|
If there is a problem with the svg itself, the change suggestion should be displayed as an error, so I suspect that the link to the svgo module on the CI side is broken. I think the svg is fine as it is. |
|
added a newline at the end of svg file, the cl tests would work now ig. |
Adds a new editor setting editors/animation/insert_at_current_time and a toggle button in the Animation Track Editor to let users choose whether to insert keys and markers at the current timeline cursor (when enabled) or at the mouse position (default behavior). - Key insertion - Paste and duplicate operations - Editor setting persistence - Icon by @TokageItLab Fixes godotengine#103272
|
Resolved merge conflicts and force pushed it. |
|
Thanks! Congratulations on your first merged contribution! 🎉 |

Summary
Adds a toggle button in the Animation Track Editor that allows users to choose between inserting animation keys and markers at the timeline cursor position or at the mouse position.
Changes
editors/animation/insert_at_timeline_cursoreditor setting to persist toggle stateFixes #103272
Demo
godot_insert_timeline_button_demo.mp4
Bugsquad edited: