Autoload Tween Class?

Godot Version



I just watched a few videos about Tweens and I’m excited to make some obvious mistakes that will bite me hard in about a month!

Here’s my thinking: if I want stylistic consistency and maintainable code, I should make an autoload class that has a function for each tween that I might want to use in the game (ex. modulate red, plus icon shake, for “you’re out of this item”, “you made a mistake” etc). I pass in the affected Sprite as an argument.

BUT! If I do that, it would break if the same tween function got called in rapid succession, UNLESS I used a tween pool? And now I don’t know if this is worth it.

Should I just use the autoloader to maintain constants like transition styles, durations, colors, etc?

Is there a general best-practice here?

Many thanks for any advice!

Tweens are not meant to be reused, so your autoload functions would have to create a new tween every time they’re called. So no pooling or using the same tween, but on the upside multiple quick calls wouldn’t interfere

From the docs:
Note: Tweens are not designed to be re-used and trying to do so results in an undefined behavior. Create a new Tween for each animation and every time you replay an animation from start. Keep in mind that Tweens start immediately, so only create a Tween when you want to start animating.

1 Like

Aha, gotcha. For some reason I thought that the function namespaces would overlap and cause mayhem, but I just tested it, and they don’t. This is great! Thanks very much!

1 Like