Forum rules - please read before posting.

Suggestion: Gradually change variable value


I would like to ask for a feature for the 'Variable:set' action, to make 'increasing by value' method smooth during time, if possible, please.

I mean, an ability to increase/decrease float or integer variables during time and with curve, like it is designed, for instance in the camera control action with ability to fade out with the transition curve and transition time in seconds.

Or, is it possible to achieve smooth variable change with the formula?

I want to use this mainly for non-linear change of connected animation float parameters, but pretty sure such feature could be useful for other scenarios, like changing in-game stats through animation curve.

Will be glad for any feedback, thank you so much!


  • edited July 2022

    Welcome to the community, @Conmu.

    It's possible to place this Action type inside a loop, preceded by a Variable: Check Action that checks if the value is less/greater than the intended final value. If this is followed up by an Engine: Wait Action that waits -1s, it'll wait for exactly one frame before running again:

    If you move these Actions to an ActionList asset file, you can parameterise the Variable and Integer fields so that you can use it whenever you want to increase a given Integer variable to some maximum value. ActionList parameters are a way of recycling ActionLists by altering their field values at runtime - a tutorial can be found here.

  • Good day Chris and thank you so much for your answer!

    Yes, honestly I am using such method already and using parameters in my ActionLists widely as well, but unfortunately such method is still linear - the value will increase with the constant step during time, like that:
    0 > 0.1 > 0.2 > 0.3 > 0.4 > 0.5 > 0.6 > 0.7 > 0.8 > 0.9 > 1

    What I want to achieve is non linear changing of a variable, like as if its value would controlled with the time curve with smoothing interpolations. In this case the value would change, for instance, like that:
    0 > 0.034 > 0.126 > 0.259 > 0.417 > 0.583 > 0.741 > 0.874 > 0.966 > 1

    That's why I mentioned 'Camera:Fade' action as an example of ActionList, where transition curve can be used to make fade effect non-linear during time.

    Maybe it is possible to change variable in non-linear way with the formula?

    Thank you!

  • Not with the Formula option, no - that's still a single-use method.

    Variables can be set via script, however. It's possible to write a custom script that makes use of an AnimationCurve - like the "Camera: Fade" option does - to update a variable's value over time:

    using System.Collections;
    using UnityEngine;
    using AC;
    public class VariableSmoothSet : MonoBehaviour
        public AnimationCurve valueCurve;
        public Variables variables;
        public string variableName;
        GVar variable;
        public void Interact ()
            variable = (variables != null) ? variables.GetVariable (variableName) : GlobalVariables.GetVariable (variableName);
            if (variable == null) return;
            Kill ();
            StartCoroutine (ChangeCo ());
        public void Kill ()
            StopAllCoroutines ();
        private IEnumerator ChangeCo ()
            float t = 0;
            float totalDuration = valueCurve.keys[valueCurve.length-1].time;
            while (t < totalDuration)
                float value = valueCurve.Evaluate (t);
                variable.FloatValue = value;
                variable.IntegerValue = (int) value;
                t += Time.deltaTime;
                yield return null;

    Try this. Place inside a C# file named VariableSmoothSet.cs and attach to a GameObject (can be a prefab). If you supply a Variables, it'll affect a component variable. Otherwise, a Global Variable.

    To use it, reference it with the Object: Send message Action, passing in the Interact method to start it, and Kill to stop it.

  • Thank you so much Chris, you really have made my day!

    It works as I asked, just took some time for me to figure out that duration of variable change controlled via keys in the curve editor as well.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.