Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation Player: reset track properties not present in current animation to RESET values #6417

Open
hsandt opened this issue Mar 3, 2023 · 2 comments

Comments

@hsandt
Copy link

hsandt commented Mar 3, 2023

Describe the project you are working on

A platformer with 2D sprite animations

Describe the problem or limitation you are having in your project

Extra track properties not present in all my animations, such as brightness value, are not reset to their default values set in scene nor to RESET animation values when switching from an animation using them to a new animation not using them.

This causes leftover properties as in the GIF below where the character keeps their Hurt animation brightness after restart to Fall and Idle animation:

2023-03-03 Godot 4 - Animation Player: reset track properties not present in current animation to RESET values

When Hurt animation overrides brightness:

image

but Fall and Idle do not:

image

I added the tracks to RESET animation, to no avail:

image

According to the documentation, this is by design as RESET is only used when Saving in editor.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Adding an option to AnimationPlayer to reuse RESET property values as default track animations would make runtime benefit from this nice editor feature.

This is similar to Unity's "Write Defaults" property (https://docs.unity3d.com/Manual/class-State.html), which is very convenient to avoid defining the same extra properties on every animation when only a minority of them really need to animate them.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

  • Add AnimationPlayer exposed property use_reset_animation_as_default or something like this.
  • If checked:
    • on start, any property present in RESET but not set in the first animation uses the RESET animation value
    • on animation change, any property set in RESET but not the new animation is reverted to the value in RESET animation (we could also only set it if it was actually set by the previous animation; but it won't reset it if we changed said property as runtime via code, which may be desired or not depending on design)

Note: for blended transitions we'd need to think a little more how to work. I suggest to use the RESET animation value as if it was actually defined in the target animation not having it, and blend toward it.

If this enhancement will not be used often, can it be worked around with a few lines of script?

It can be worked around via code by switching to RESET animation, forcing properties refresh then switching to wanted animation. I tested the following code below and it works:

animation_player.play(&"RESET")
animation_player.advance(0)
animation_player.play(animation_name)
# extra advance required if you do this at the end of the frame,
# e.g. in _on_animation_player_animation_finished callback,
# to avoid showing default state for 1 frame
animation_player.advance(0)

Alternatively, if you know which extra properties are missing from some animations, you can manually reset them in code.

It can be worked around by changing data, but you need to add missing properties to every animation.

Is there a reason why this should be core and not an add-on in the asset library?

Yes, it's adding a field to built-in AnimationPlayer.

@timothyqiu
Copy link
Member

timothyqiu commented Mar 25, 2023

I was about to make the same proposal.

Currently, my approach to solve the problem is to go through all the existing animations and add a keyframe manually :(

Edit: Created a plugin to "define the same extra properties on every animation" https://github.com/timothyqiu/godot-animation-resetter

@hsandt
Copy link
Author

hsandt commented Mar 1, 2024

@timothyqiu I checked your addon again but it says it's not required anymore with the new deterministic flag (apparently added in godotengine/godot#80813), so maybe I can close this issue (I will test it first in my project to be sure).

That said, the deterministic flag was really focused on blending float properties and it seems that applying proper reset on properties in general was more like a side effect of it, which is great but not really explained in the tooltip. So it may be good to explain it better in the tooltip / documentation so people who want to force RESET properties know what to do.

In addition, there may be some devs who need to RESET properties but don't want deterministic blending (I don't have an example in mind, since I'm working with non-blended frame-by-frame animations), in which case we may prefer yet another flag to force property reset.

So I'll keep this issue open for now. I'd like to gather more feedback from other devs to know what they want too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants