Forum rules - please read before posting.

Pausing/Resuming all ActionLists currently running?

I have a clock actionlist running in the background, and I want it to trigger a save game action every in-game hour. This is very easy to do, but the problem is that the game won't save if the player happens to have any game-blocking cutscenes running at the time. Is there a way for an actionlist to pause all other actionlists currently running (without needing to specify which), run the save action, and then resume all the actionlists that were paused a few moments before?

Comments

  • ActionLists can indeed be paused and resumed, but I think you'd end up facing the issue that prevent saving when gameplay is blocked in the first place.

    This restriction is in place because while the state of ActionLists themselves can be recorded (when paused), it's actually the state of the objects that they affect that matter.

    Unless you opt to wait for current Actions to finish when pausing, you're going to have certain discrepencies appear when saving/loading. For example, a character might by midway through a pathfinding operation that then gets cancelled - causing them to appear in the wrong place upon loading.

    If you deem it acceptable, it would be safer to simply delay the save call until the next time the game re-enters normal gameplay. This can be done by hooking into the OnEnterGameState custom event:

    using UnityEngine;
    using AC;
    
    public class SaveInGameplay : MonoBehaviour
    {
    
        public ActionListAsset saveActionList;
        private bool delaySaving = false;
    
        private void OnEnable () { EventManager.OnEnterGameState += EnterGameState; }
        private void OnDisable () { EventManager.OnEnterGameState -= EnterGameState; }
    
        public void AttemptToSave ()
        {
            if (KickStarter.stateHandler.IsInGameplay ())
            {
                Save ();    
            }
            else
            {
                delaySaving = true;
            }
        }
    
        private void Save ()
        {
            delaySaving = false;
            saveActionList.Interact ();
        }
    
        private void EnterGameState (GameState _gameState)
        {
            if (_gameState == GameState.Normal && delaySaving)
            {
                Save ();
            }
        }
    
    }
    

    Attach that to an empty GameObject, make it a prefab, and assign the ActionList that saves the game in its Inspector. Then, call its AttemptToSave function using an Object: Call event Action when you want to save when in gameplay.

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.