Forum rules - please read before posting.

Scene-surviving Action List in background persists, but doesn't resume

edited July 2019 in Technical Q&A

I'm trying to track how long players need to perform certain tasks in the game. I've created an Action List that starts with the game and it's just a simple loop of "Engine: Wait 1s" and "Integer Variable += 1".

The Action List runs fine in my Main Menu scenes but as soon as I load up the first game scene it just stops. It still shows up as running in the status box, it also persists through the scene changes, but AC is not executing the actions in the list.

I tried to work around it by creating an Action List in every scene that uses the same variable, but even when I have the List run in the background, as soon as anything else changes the game state to "paused" the Action List is also paused, which makes keeping track of time passed impossible.

Is there a way to have an Action List ignore game states or somehow continue running in the background when the game is paused? I'll try create a background timer in a clean project, similar to how it's setup in my current project.

Maybe you already know what the problem is, maybe the issue is fixed in 1.65.3 (I can only update to 1.68, but that will probably cause other new issues...).

This is an issue I have using AC 1.65.0 and Unity 2018.2.9f1.
The project was originally created using AC 1.60.0 and Unity 2017.2.3f1.
I worked through the entire games and fixed all the issues I had after the update, but this one is a bummer.

Maybe someone has an idea what's happening? I don't think it's an issue with scene surviving action lists per se as that would've been raised and fixed etc.

Comments

  • When you say you "load up" the first game scene, how is that achieved? Are you using a Scene: Switch Action, or actually loading a save game file?

    This may well have been addressed already - I can't recreate the issue if it's the former, and if it's the latter then the ActionList shouldn't be running after loading (though this can be re-run by hooking into the OnFinishLoading custom event).

    However, scene-surviving ActionLists are more intended for situations where you want a single cutscene to span multiple scenes - rather than running for the entirety of your game. If all you're looking to do is increase an Integer variable's value every second, I'd say that's best done with a simple script:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class TimerExample : MonoBehaviour
    {
    
        public int variableID = 0;
        public float waitTime = 1f;
    
        private float timer;
    
    
        private void Start ()
        {
            DontDestroyOnLoad (this);
            timer = waitTime;
        }
    
    
        private void FixedUpdate ()
        {
            timer -= Time.fixedDeltaTime;
            if (timer <= 0f)
            {
                timer = waitTime;
                GVar myVariable = GlobalVariables.GetVariable (variableID);
                myVariable.IntegerValue += 1;
            }
        }
    
    }
    
  • Thank you for the quick response. I tried using the suggested method, but it seems that whenever the game state is paused, no more Update functions are called.

    I've written a custom action that just looks at the clock, converts the current time to seconds and I can declare a variable to store the integer value. I can use the action to store time in seperate variables to compare later on. As long as people don't play at around midnight, everything should work fine...

  • There is no Update function in the above code - FixedUpdate should be fine. A coroutine could also be used.

  • That's weird.

    I added the script to GameManager and then AudioManager - as they are both scene surviving objects. I tested Update, FixedUpdate and LateUpdate, they were all stopped during game state paused.

  • As neither GameManager nor AudioManager are AC objects, I don't know what you're referring to. The script itself, however, marks the object it's attached to as scene-surviving - you can attach it to a fresh Empty.

    My mistake about FixedUpdate - it should be in Update. It may be that its running, but the effects aren't being felt somehow. Try inserting a Debug.Log statement - replace the FixedUpdate function above with:

    private void Update ()
    {
        timer -= Time.fixedDeltaTime;
        if (timer <= 0f)
        {
            timer = waitTime;
            GVar myVariable = GlobalVariables.GetVariable (variableID);
            myVariable.IntegerValue += 1;
            Debug.Log ("Increased " + myVariable.label + " by 1. Value = " + myVariable.IntegerValue);
        }
    }
    
  • Thanks! When I get around to it I'll test it and report back.

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.