Does Unity have "Actions" or "Sequences?"

I’m moving to Unity from a different in-house engine and one thing I’ve been looking for are Action Sequences.

In my old engine, I could essentially type something like this: Action(sequence, original value, target value, time, ease method) It’s similar to how a lerp function would work. This one in particular is only called once (like within the start function) and would immediately play the next Action in a particular Sequence. It was amazing for cutscenes and UI things like fade-in and fade-out.

Basically, I’m looking for a way to change a number slowly into a new number. Instead of popping from 1 to 5, it would start at 1, and depending on the time you set, would go through 2, 3, and 4 until it got to 5.

I’m sure there are a few ways this could be approached, but from what information you’ve provided, I’d suggest using a simple coroutine. Here’s a quick, dirty example…

public int myNumber = 0; // the number you wish to slowly increment
public float waitTime = 10.0f; // the time, in seconds, you wish to wait between number changes
private int lastNumber = 0; // variable to check against the current number so we can tell when it's changed

   void Start()
   {
     StartCoroutine(GoNext()); // start our timer coroutine counting down
   }

   void Update()
   {
     if(myNumber < 5) // only run the following until myNumber reaches 5
     {
       if(lastNumber != myNumber) // if our recorded lastNumber variable isn't the same as the current myNumber value
       {
         StartCoroutine(GoNext()); // assume the number has changed & start the timer again
       }
     }
   }

   IEnumerator GoNext()
   {
     yield return new WaitForSeconds(waitTime); // wait however many seconds
     myNumber++; // add 1 to myNumber
   }

Now, I’ve no idea if this is what you’re really looking for or not, but I thought it might help. There are likely more elegant solutions as well, but I’m still fairly new to coding (though I’m old hat at reverse engineering, haha), so I can only help so much.

That’s interesting.
The “Action Sequence” function I’m looking for was some sort of custom function in the engine. I don’t think this is quite what I’m looking for.
If you are familiar with the math “lerp” function, it behaved more like that, but used “eases” instead of lerping. It looks like what you wrote skips decimals and has no way of easing between values.

Oh sure, Unity’s got Mathf.Lerp (and Slerp I believe), among other things, and of course you could use floats instead of ints and increment them in whatever tiny manner you’d like. You could have the number constantly grow by a small fraction by adding to it in Update or any number of things. What I showed is just one example of how such a thing can be done. I was simply illustrating the example you provided in your question. Sorry it wasn’t of use to you.

If you’re interested, here’s a link to the various Mathf functions Unity supports:

and here are the docs on Mathf.Lerp (with C# and JS examples):

You’re looking for what is often called a ‘tween’ engine.

There are many tween engines out there.

Mine is called SPTween and is found in my Spacepuppy Framework:

example usage is like:

SPTween.PlayFromTo(transform, "position.y", EaseMethods.BounceEaseOut, start, end, dur);

or for more complex situations, I have a functional approach. Here I tween several different things (mostly opaqueness of some sprites, and some text in a text field):

SPTween.Tween(_bg)
      .SetId(this.GetInstanceID())
      .RedirectTo("color.a", EaseMethods.LinearEaseIn, 0f, 1f, this.TransitionFadeDur)
      .AutoKill()
      .Play();
_image.enabled = true;
_image.sprite = Sprite.Create(data.Image, new Rect(0f, 0f, data.Image.width, data.Image.height), Vector2.zero);
SPTween.Tween(_image)
      .SetId(this.GetInstanceID())
      .RedirectTo("color.a", EaseMethods.LinearEaseIn, 0f, 1f, this.TransitionFadeDur)
      .AutoKill()
      .Play();

_text.enabled = true;
_messageTextTween = SPTween.Tween(_text)
                          .SetId(this.GetInstanceID())
                          .RedirectTo("color.a", EaseMethods.LinearEaseIn, 0f, 1f, this.TransitionFadeDur)
                          .AutoKill("color.a")
                          .OnFinish((s, e) => _messageTextTween = null)
                          .Play();
textTweenDur = com.spacepuppy.Tween.Curves.StringCurve.CalculateDuration(string.Empty, data.Message, data.Speed);
SPTween.Tween(_text)
      .SetId(this.GetInstanceID())
      .FromTo("text", EaseMethods.LinearEaseIn, string.Empty, data.Message, textTweenDur, StringTweenStyle.Default)
      .AutoKill()
      .Play();

Others include iTween:
http://itween.pixelplacement.com/index.php

HOTween:

DOTween:

And there are more.

1 Like

Oh, wow! That’s exactly what I was looking for. Didn’t know what it was called.
Thank you for the info!