Tween a number in a global variable

Since there is an ability to tween a number value in objects and scenes, it would be great to be able do the same with Global variables. Would allow a lot more flexibility in how we’re setting up our projects.

You are right that the gap is real, and it is small enough that I would call it a missing action rather than a missing feature. Here is what is actually there as of 5.6.280, plus two ways to get it today.

What ships now

The Tween behavior registers number tweens for exactly three things: object properties, scene variables (TweenSceneVariableNumber3, parameter type scenevar), and object variables (AddObjectVariableTween3, parameter type objectvar). There is no globalvar variant. And the scene-variable picker only lists scene variables, so you cannot route a global through it either.

Option 1, no code: tween a scene variable, mirror it into the global

  • Once: Tween a number in a scene variable, id tweenFoo, variable FooTween, to 100, easing easeInOutQuad, 1.5 seconds.
  • Every frame: Change global variable Foo = Variable(FooTween).

The mirror reads the current value, not last frame’s. The extension steps its tween manager in a scene pre-events callback, so by the time your events run, the scene variable already holds this frame’s value.

Option 2, JS event: tween the global directly

The runtime function takes any Variable, globals included:

const v = runtimeScene.getGame().getVariables().get("Foo");
gdjs.evtTools.tween.tweenVariableNumber3(
  runtimeScene, "tweenFoo", v, 100, "easeInOutQuad", 1.5
);

Two details that bite:

  1. tweenVariableNumber3 starts from the variable’s current value and takes duration in seconds. The older tweenVariableNumber takes milliseconds plus an explicit from, and it is deprecated.
  2. It does nothing at all if the variable’s type is not number (if (variable.getType() !== 'number') return;). If Foo was created as a string that looks numeric, the tween silently never runs.

If you want the action itself

It is a small change: a globalvar twin of the scene-variable action that resolves the variable from the game container (runtimeScene.getGame().getVariables()) instead of the scene one. Worth filing at Issues · 4ian/GDevelop · GitHub so it gets tracked. Feature requests there do get picked up, and this one has a clean scope.