Forum rules - please read before posting.

How to correctly use "defaultPauseTime" in custom action?

edited March 7 in Technical Q&A

Hello, I am trying to Mathf.Lerp some float values in a custom action. I am doing this:

override public float Run ()
        {// Do the graduate changes
                t = 0f;
            while (t <= 1) {
                for (i = 0; i < 4; i++) {
                    for (int j = 0; j < 5; j++) {
                        CM4x5 [i, j] = Mathf.Lerp (iniCM4x5 [i, j], final_CM4x5_array [i, j], t);
                t += Time.deltaTime / timeOfChange;
                Debug.Log (t + " " + CM4x5 [0, 0]);
                return defaultPauseTime;

            return 0f; // Wait time = 0s

But the Debug.Log only output once with t = 0.003599046. How can I make it run until t > 1?



  • But I got another question: How to implement the "wait until finish?" option for both the cases of checked and checked?

  • edited March 9

    "defaultPauseTime" will cause the Action to be re-run the next frame.

    To have an Action run every frame until a given max time, initialise the timer when the Action is first run, e.g.:

    float timer;
    public override float Run ()
        // Do whatever you want to do per-frame here
        if (!isRunning)
            timer = 1f;
            isRunning = true;
            return defaultPauseTime;
        timer -= Time.deltaTime;
        if (timer <= 0f)
            isRunning = false;
            return 0f;
        return defaultPauseTime;

    How to implement the "wait until finish?" option for both the cases of checked and checked?

    What counts as "finished" will depend on the Action itself. If it's unchecked, the behaviour of "official" AC Actions is that it will run for one frame only - so it'll always return "0f".

    If you want the Action to have an effect over multiple frames, but have the Action itself only run for a single frame, then move the effects of the Action into a separate C# script and have the Action trigger a function within that script.

    See, for example, the way the Camera: Fade Action (ActionFade.cs) calls the MainCamera's FadeIn / FadeOut functions to perform the actual fading effect.

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.