#whats the best way to pause the game when making an DOTS game?

1 messages · Page 1 of 1 (latest)

graceful gate
#

ive tried disabling all systems running in the same group. and while this works, unpausing seems to "catch up" in a way

my thought is, because im using jobs, the jobs cannot be stopped, but how to work around this?

using Unity.Entities;
using Unity.Physics.Systems;
using UnityEngine;
namespace MonoBehaviors
{
    public class PauseManager : MonoBehaviour
    {
        private FixedStepSimulationSystemGroup fixedStepSimulationSystemGroup;
    
        public bool isPaused = false;

        void Start()
        {
            World world = World.DefaultGameObjectInjectionWorld;
            fixedStepSimulationSystemGroup = world.GetOrCreateSystemManaged<FixedStepSimulationSystemGroup>();
        }

        void Update()
        {
            if (Input.GetKeyDown(KeyCode.P))
            {
                isPaused = !isPaused;
                fixedStepSimulationSystemGroup.Enabled = !isPaused;
                Debug.Log($"Paused: {isPaused}, Simulation Group Enabled: {fixedStepSimulationSystemGroup.Enabled}");
                
                
            }
        }
    }
}```

sorry if this is a dumb question
shell river
#

you need to pause the time updates

#

and keep resetting htem

#

otherwise it'll just catch up all the fixed updates when you unpause

graceful gate
#

oh i see! ill give this a tryt

graceful gate
junior lance
#

There's also the option of setting the timescale to 0, but then your game needs to be built around that. But custom rate manager/wrapper like what Tertle has is probably best yeah.