# AnimationPlayer doesn't interpolate shader parameter

**URL:** <https://forum.tsuki.games/t/animationplayer-doesnt-interpolate-shader-parameter/106>\
**Category:** Q&A\
**Tags:** godot\
**Created:** [May 5, 2024, 8:36am UTC](https://forum.tsuki.games/t/animationplayer-doesnt-interpolate-shader-parameter/106 "2024-05-05T08:36:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![exodrifter](https://tsuki.b-cdn.net/user_avatar/forum.tsuki.games/exodrifter/32/3_2.png) [@exodrifter](https://forum.tsuki.games/u/exodrifter)\
**Post date:** [May 5, 2024, 8:36am UTC](https://forum.tsuki.games/t/animationplayer-doesnt-interpolate-shader-parameter/106/1 "2024-05-05T08:36:24Z")

</div>

I ran into an issue recently in Godot 4.2.1 where the `AnimationPlayer` doesn’t seem to interpolate the value of a shader parameter between key frames.

I verified that:

- The update mode of the track is set to `Continuous`.
- The interpolation mode of the track is set to `Linear`.

As you can see in the below example, the value of the `Elapsed` parameter is still `0` despite the `AnimationPlayer` playhead being halfway between two keys, which are set to the values `0` and then `0.5`.

![The inspector is on the left showing the elapsed shader parameter which is currently set to 0. On the right, the Animation editor is visible and there are two key frames at the 0 second and 1 second marks. The playhead is placed at the 0.5 second mark.](https://tsuki-s3.b-cdn.net/original/1X/a0f57f3f835b7c900f8895082f2cd1f4c27c6af4.png)

I would expect to see the value set to `0.25`, but the value is still `0`. If I move the playhead to the end, the value is set to `0.5`. So, it appears interpolation is not working. Making tracks for other properties interpolates as expected. How do I get it to interpolate?

---

<div class="post-metadata">

**Author:** ![exodrifter](https://tsuki.b-cdn.net/user_avatar/forum.tsuki.games/exodrifter/32/3_2.png) [@exodrifter](https://forum.tsuki.games/u/exodrifter)\
**Post date:** [May 5, 2024, 8:48am UTC](https://forum.tsuki.games/t/animationplayer-doesnt-interpolate-shader-parameter/106/2 "2024-05-05T08:48:16Z")

</div>

If you add a new key frame when the shader parameter is set to the default value, Godot actually emits a warning. For example:

> scene/animation/animation\_mixer.cpp:879 - AnimationMixer: ‘spin’, Value Track: ‘.:material:shader\_parameter/elapsed’ uses a non-numeric type as key value with UpdateMode.UPDATE\_CONTINUOUS. This will not be blended correctly, so it is forced to UpdateMode.UPDATE\_DISCRETE. (User)

You can also see that the key frame is set to a null value instead of the default value if you hover over it instead of looking at the value of the key frame in the inspector:

![A mouse cursor is hovered over the first key frame in an animation player, showing that the type of the key frame is nil and that the value is null.](https://tsuki-s3.b-cdn.net/original/1X/7de12ab2fd13f23040be8ed04447a9b34aaa3733.png)

Apparently, this is a tracked as [#87040](https://github.com/godotengine/godot/issues/87040) in the Godot issue tracker and has not been fixed yet. To get around the issue, set the affected key frames to a non-default value. You can then set the value back to the default value in the inspector for the key frame. This will cause Godot to set a non-null value for the key frame.

![A mouse cursor is hovered over the first key frame in an animation player, showing that the type of the key frame is float and that the value is 0. The playhead is placed at the 0.5 second mark and the corresponding shader parameter is set to 0.25 as expected.](https://tsuki-s3.b-cdn.net/original/1X/8517037b6dabcf9b25b3386a33fc8f51758afab2.png)

**Note:** You have to set _all_ key frames in _all_ animations in order for this workaround to work. When I first tried doing this, I found that the interpolation for my animation still wouldn’t work because the `RESET` animation still had a key frame with null values.

---

<div class="post-metadata">

**Author:** ![Titanseeker](https://tsuki.b-cdn.net/user_avatar/forum.tsuki.games/titanseeker/32/31_2.png) [@Titanseeker](https://forum.tsuki.games/u/Titanseeker)\
**Post date:** [May 6, 2024, 3:03pm UTC](https://forum.tsuki.games/t/animationplayer-doesnt-interpolate-shader-parameter/106/3 "2024-05-06T15:03:31Z")

</div>

does godot allow you to run events through the animation tracker? if so, you could run an event in there as well :Y

also throbber

---

<div class="post-metadata">

**Author:** ![exodrifter](https://tsuki.b-cdn.net/user_avatar/forum.tsuki.games/exodrifter/32/3_2.png) [@exodrifter](https://forum.tsuki.games/u/exodrifter)\
**Post date:** [May 6, 2024, 5:22pm UTC](https://forum.tsuki.games/t/animationplayer-doesnt-interpolate-shader-parameter/106/4 "2024-05-06T17:22:37Z")

</div>

I’m not sure what you mean by “event”, but you can indeed call methods from `AnimationPlayer`. However, this would still not let interpolation happen automatically as [the method would only be called once when the keyframe happens](https://docs.godotengine.org/en/4.2/tutorials/animation/animation_track_types.html#call-method-track).

You could probably use that approach to work around the problem, but it would involve making the method implement its own interpolation inside a coroutine.

---

<div class="post-metadata">

**Author:** ![exodrifter](https://tsuki.b-cdn.net/user_avatar/forum.tsuki.games/exodrifter/32/3_2.png) [@exodrifter](https://forum.tsuki.games/u/exodrifter)\
**Post date:** [May 13, 2024, 5:22pm UTC](https://forum.tsuki.games/t/animationplayer-doesnt-interpolate-shader-parameter/106/5 "2024-05-13T17:22:44Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
