godotengine / godot

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

Animated Texture stopping #69621

Open Zettexe opened 1 year ago

Zettexe commented 1 year ago

Godot version

Godot 4 Beta 6

System information

Windows 10, Vulkan, NVIDIA GeForce RTX 2080 Ti (527.37)

Issue description

After leaving the game running in the background for a while the animated textures seem to stop completely most of the time but sometimes they are only stopped for a moment then speed up to seemingly catch up.

Steps to reproduce

Put Sprite2D with an animated texture as the texture Launch game and leave it in the background Eventually it will either desync or stop the animations completely

Minimal reproduction project

minimal-reproduction.zip

Calinou commented 1 year ago

@Zettexe Please upload a minimal reproduction project to make this easier to troubleshoot.

TokageItLab commented 1 year ago

Guessing from previous contributors chat discussions, should Animated Texture be marked as deprecated? @reduz

Mickeon commented 1 year ago

Reduz wanted to nuke it next time which would be unfortunate, if it can't be overhauled to work properly. Anyway, it would be nice to have a minimal reproduction project, but I know what OP is referring to.

Due of the implementation of AnimatedTexture (which I did not touch in #65188) I noticed a silly flaw. Whenever you tab out, AnimatedTexture stops "ticking". Wait for enough time where the next frame should've arrived, but it does not. Then you tab in, and the next frame switches instantly. This makes perfect sense in theory, as a result of its implementation.

Every rendered frame that passes, AnimatedTexture checks if enough time has passed, to switch to the next frame. That is it. It does not skip any additional frames depending on how much time has actually passed, only one per frame. This can also theoretically make the timings of an AnimatedTexture inconsistent with very variable framerates. The problem here is also likely caused by the fact that there isn't much redrawing when unfocused, too (which is an optimisation).

The "frame jumping" could be fixed by having the current frame be based on a constant "timeline" that loops consistently. It's not easy, but it is definitely doable (I'd gladly do it, for one). It may even be more optimised than it currently is.

Zettexe commented 1 year ago

Updated the original post with a minimal repro, easiest way to see the issue is to minimize the running game for a couple minutes then come back to it. The longer you wait the longer it takes for the Animation to restart.

MewPurPur commented 1 year ago

@Mickeon So should AnimatedTexture get the "is_experimental" flag perhaps, then?

Mickeon commented 1 year ago

"Deprecated" sounds more suitable. A shame, however.

eh-jogos commented 1 year ago

I don't know where the conversation for deprecating AnimatedTexture is happening, but I found it useful to use in TextureRects to have GUI with simple animations looping. It was much cleaner than mixing Controls with Node2Ds, and also easy to make them responsive.

I don't know if this is a use case that is common enough to "save" this resource from being deprecated, but it was a pretty neat use case that I don't know if there is an easy alternative to it.

golddotasksquestions commented 1 year ago

In Godot 4.0.2 AnimatedTexture on a Sprite works for me fine when I run the scene, but in the Editor it seems to "stutter". When I tab focus between the Editor and other running software, it stops completely (in the editor, when I run the project it runs fine).

Since it is a resource which is has the same broad spectrum of application as a regular texture, and is very simple an easy to use, it would be a loss to depreciate it without adequate replacement. If we could something like SpriteFrames instead as a animated texture, that would be cool.

Calinou commented 1 year ago

but in the Editor it seems to "stutter". When I tab focus between the Editor and other running software, it stops completely (in the editor, when I run the project it runs fine).

The editor is capped to 10 FPS when unfocused by default. Adjust Unfocused Low Processor Mode Sleep Usec in the editor settings to change this.

golddotasksquestions commented 1 year ago

The editor is capped to 10 FPS when unfocused by default. Adjust Unfocused Low Processor Mode Sleep Usec in the editor settings to change this.

That's not the issue I'm talking about @Calinou The stuttering is with the Editor always in focus. Like you create a completely new scene, add a Sprite, add an AnimatedTexture of at least two frames -> irregular stutter of the AnimatedTexture playback. When I then Alt-tab away from the Godot Editor (on MS Windows), and then Alt-tab back to the Godot Editor, the AnimatedTexture won't play at all anymore. So it can't have anything to do with the 10FPS cap when unfocused, since the Editor is in focus, and AnimatedTexture has been stuttering even before ever leaving focus.

Sethyh commented 1 year ago

The editor is capped to 10 FPS when unfocused by default. Adjust Unfocused Low Processor Mode Sleep Usec in the editor settings to change this.

That's not the issue I'm talking about @Calinou The stuttering is with the Editor always in focus. Like you create a completely new scene, add a Sprite, add an AnimatedTexture of at least two frames -> irregular stutter of the AnimatedTexture playback. When I then Alt-tab away from the Godot Editor (on MS Windows), and then Alt-tab back to the Godot Editor, the AnimatedTexture won't play at all anymore. So it can't have anything to do with the 10FPS cap when unfocused, since the Editor is in focus, and AnimatedTexture has been stuttering even before ever leaving focus.

sometimes this happens to me too... sometimes it stops to play and only plays if something makes the screen updates, like, if anything get focus like a button or option

Calinou commented 1 year ago

sometimes this happens to me too... sometimes it stops to play and only plays if something makes the screen updates, like, if anything get focus like a button or option

This is because of low-processor usage mode – AnimatedTextures don't force continuous redrawing. This is a bug, but I don't know if it can be fixed given how AnimatedTextures work.

Sethyh commented 1 year ago

I turn it on and test and turn it off again: same thing... but at least works in the game... the crazy thing is that works in 3.5.2 with no problem... with the same configs (when applicable) used in 4.0.2