godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
86.93k stars 19.47k forks source link

Light2D energy propertys do not transition when created programatically #58046

Open GarethSomers opened 2 years ago

GarethSomers commented 2 years ago

Godot version

3.4.2

System information

Windows 10, GLES3, GTX3080

Issue description

When programattically creating an animation, on the Light2D:energy property, the keyframes will not have a transition between them, instead once a keyframe is reached it's value is immediately applied in full.

By "transition" I mean there is no interpolation, there is not effect.

Steps to reproduce

Simple example:

var anim_player = AnimationPlayer.new() 
anim_player.name = "AnimationPlayer"
self.add_child(anim_player)

var fade = Animation.new()
anim_player.add_animation("day_to_night", fade)
fade.length = 10

var track_index = fade.add_track(0)
fade.track_set_path(track_index, "Light2D:energy")
fade.track_insert_key(track_index, 0, 0)
fade.track_insert_key(track_index, 10, 1)

I then played the scene, paused the scene, went into "Remote" node explorer, found the AnimationPlayer and saved it's branch as a Scene.

I opened the saved AnimationPlayer, manually inserted it into the corrosponding Scene with the Light2D(s), fixed up the node path references in the Animation (e.g. /Root/Some/Path/To/Light2D:energy to Light2D:energy). Then inspected the Animation in the editor.

The Animation in the editor works incorrect, same as in game, in that the keyframes are fired asif there is no transition (no interpolation?) between them.

Minimal reproduction project

light2d-issue.zip

allenwp commented 1 year ago

I was able to reproduce this issue using the attached reproduction project with v3.4.4.stable.official [419e713a2].

The issues seems to happen exclusively when both the start end end values are integers. Setting either or both of these values to a float value causes the Light2D:energy property to correctly interpolate.

Here is the GDScript showing the issue and the resolution using float variables:

# Github issue #58046 reproduction:
var start: int = 1
var end: int = 0

# Fix for issue that interpolates correctly:
#var start: float = 1
#var end: float = 0

# Alternative fix for issue that interpolates correctly:
#var start: float = 1
#var end: int = 0

# Alternative fix for issue that interpolates correctly:
#var start: int = 1
#var end: float = 0

fade.track_insert_key(track_index, 0, start)
fade.track_insert_key(track_index, 10, end)

I literally just started working with Godot a couple of days ago, so I'm not sure what the resolution for this issue should be, but my gut says that this is actually intended behaviour: The animation system seems to be correctly interpolating between integers, as it was asked to.

Unless maybe the animation system should perform casts to the final property type before interpolating? I'm not sure what the best behaviour is here.

TokageItLab commented 1 year ago

I guess for int values, the default is DISCRETE track, so I think I just need to make it CONTINUOUS manually. Maybe it is a documentation issue.