Topic: Pause Everything On Pause?

Just wondering, is it possible to pause everything including particles whenever you pause a match? The problem I'm having is when you pause a match, any particles(hit effects, projectile) in the scene continue to play to their end while leaving their hitbox in place. When you resume the hitbox still hits though.

Share

Thumbs up Thumbs down

Re: Pause Everything On Pause?

Try using

Time.timeScale = 0;

But make sure you have "Use FixedUpdate for Inputs" disabled under Global -> Advanced Options.

Like UFE? Please rate and review us on the Asset Store!
Questions about the Forum? Check out our Karma FAQ.

Re: Pause Everything On Pause?

Thank you Mistermind, will try.

Share

Thumbs up Thumbs down

Re: Pause Everything On Pause?

Mistermind wrote:

Try using

Time.timeScale = 0;

But make sure you have "Use FixedUpdate for Inputs" disabled under Global -> Advanced Options.

I've tried this with my project, and it does indeed freeze my projectiles & particles, but when the game is paused I can't adjust the pause menu without using my mouse. Is there a fix for this? Would be greatly appreciated.

Share

Thumbs up Thumbs down

Re: Pause Everything On Pause?

Im having the same issues, did you ever figure out how to get input working right on pause?

Share

Thumbs up Thumbs down

Re: Pause Everything On Pause?

You may want to cherry pick what you want to pause and make a script to handle that.
It's what I did.

I just checked when UFE.IsPaused() is true
then did what I needed from there

Share

Thumbs up Thumbs down

Re: Pause Everything On Pause?

Thanks, Ill take a crack at that smile

Share

Thumbs up Thumbs down

Re: Pause Everything On Pause?

Actually, could you share the script please? Might save time reinventing the wheel smile

Share

Thumbs up Thumbs down

Re: Pause Everything On Pause?

This one pauses particles

using UnityEngine;

public class UFE_2PauseParticlesHandlerScript : MonoBehaviour
{
    public ParticleSystem myParticleSystem;

    // Update is called once per frame
    void Update()
    {
        switch (UFE.isPaused())
        {
            case true:
                myParticleSystem.Pause(true);
                break;

            case false:
                switch (myParticleSystem.isPlaying)
                {
                    case false:
                        myParticleSystem.Pause(false);
                        myParticleSystem.Play(true);
                        break;
                }
                break;
        }
    }
}

Share

Thumbs up +3 Thumbs down

Re: Pause Everything On Pause?

Thanks smile

Share

Thumbs up Thumbs down

Re: Pause Everything On Pause?

Where do you place this script? And each particle?


FreedTerror wrote:

This one pauses particles

using UnityEngine;

public class UFE_2PauseParticlesHandlerScript : MonoBehaviour
{
    public ParticleSystem myParticleSystem;

    // Update is called once per frame
    void Update()
    {
        switch (UFE.isPaused())
        {
            case true:
                myParticleSystem.Pause(true);
                break;

            case false:
                switch (myParticleSystem.isPlaying)
                {
                    case false:
                        myParticleSystem.Pause(false);
                        myParticleSystem.Play(true);
                        break;
                }
                break;
        }
    }
}

Share

Thumbs up Thumbs down

Re: Pause Everything On Pause?

I don't recommend using that script it's very old.
I made some new scripts to deal with that.

This is a scriptable object you need to create one and assign it to the correct field when using the script below.

using UnityEngine;

namespace FreedTerror
{
    [CreateAssetMenu(fileName = "New GameObject Info", menuName = "FreedTerror/U.F.E. 2 F.T.E./GameObject/GameObject Info", order = 1)]
    public class UFE2FTEGameObjectInfo : ScriptableObject
    {
        public enum OrderInLayerMode
        {
            None,
            Infront,
            Behind,
            Custom
        }
        public OrderInLayerMode orderInLayerMode;
        public int orderInLayerInfront;
        public int orderInLayerBehind;
        public int orderInLayerCustom;
    }
}

Place this script on a GameObject or Prefab it's a very nice utility script to cover various situations you may encounter.

using System;
using UnityEngine;
using UFE3D;

namespace FreedTerror
{
    public class UFE2FTEGameObjectController : MonoBehaviour
    {
        #region Variables

        private ControlsScript myControlsScript;

        [SerializeField]
        private bool useUpdate = true;

        [SerializeField]
        private UFE2FTEGameObjectInfo gameObjectInfo;

        [Serializable]
        private class AnimatorOptions
        {
            [HideInInspector]
            public Animator myAnimator;
            [HideInInspector]
            public Animator[] childAnimators;
        }
        [Header("ANIMATOR OPTIONS (GAME OBJECT INFO REQUIRED)")]
        [SerializeField]
        private bool useAnimatorOptions;
        [SerializeField]
        private AnimatorOptions animatorOptions;

        [Serializable]
        private class ParticleSystemOptions
        {
            [Tooltip("DISABLES THE GAMEOBJECT IF THE PARTICLE SYSTEM IS NOT ALIVE.")]
            public bool disableGameObjectIfNotAlive;
            [HideInInspector]
            public ParticleSystem myParticleSystem;
            [HideInInspector]
            public ParticleSystemRenderer myParticleSystemRenderer;        
            [HideInInspector]
            public ParticleSystem[] childParticleSystems;
            [HideInInspector]
            public ParticleSystemRenderer[] childParticleSystemRenderers;
        }
        [Header("PARTICLE SYSTEM OPTIONS (GAME OBJECT INFO REQUIRED)")]
        [SerializeField]
        private bool useParticleSystemOptions;
        [SerializeField]
        private ParticleSystemOptions particleSystemOptions;

        [Serializable]
        private class SpriteRendererOptions
        {
            [HideInInspector]
            public SpriteRenderer mySpriteRenderer;
            [HideInInspector]
            public SpriteRenderer[] childSpriteRenderers;
        }
        [Header("SPRITE RENDERER OPTIONS (GAME OBJECT INFO REQUIRED)")]
        [SerializeField]
        private bool useSpriteRendererOptions;
        [SerializeField]
        private SpriteRendererOptions spriteRendererOptions;

        public enum GameObjectAction
        {
            Disable,
            Enable
        }
        [Serializable]
        private class CombatStanceOptions
        {
            public CombatStances[] combatStances;
            public GameObjectAction gameObjectAction;
            public GameObject[] gameObjects;
        }
        [Header("COMBAT STANCE OPTIONS")]
        [SerializeField]
        private bool useCombatStanceOptions;
        [SerializeField]
        private CombatStanceOptions[] combatStanceOptions;

        [Serializable]
        private class GameModeOptions
        {
            public GameMode[] gameModes;
            public GameObjectAction gameObjectAction;
            public GameObject[] gameObjects;
        }
        [Header("GAME MODE OPTIONS")]
        [SerializeField]
        private bool useGameModeOptions;
        [SerializeField]
        private GameModeOptions[] gameModeOptions;

        [Serializable]
        private class PlayerPausedOptions
        {
            public GameObjectAction gameObjectAction;
            public GameObject[] gameObjects;
        }
        [Header("PLAYER PAUSED OPTIONS")]
        [SerializeField]
        private bool usePlayerPausedOptions;
        [SerializeField]
        private PlayerPausedOptions[] player1PausedOptions;
        [SerializeField]
        private PlayerPausedOptions[] player2PausedOptions;

        #endregion

        // Start is called before the first frame update
        void Start()
        {
            if (useCombatStanceOptions == true)
            {
                myControlsScript = GetComponentInParent<ControlsScript>();
            }

            InitializeAnimatorOptions();

            InitializeParticleSystemOptions();

            InitializeSpriteRendererOptions();

            UpdateCombatStanceOptions();

            UpdateGameModeOptions();

            UpdatePlayerPausedOptions();
        }

        // Update is called once per frame
        void Update()
        {
            if (useUpdate == false) return;

            UpdateAnimatorOptions();

            UpdateParticleSystemOptions();

            UpdateCombatStanceOptions();

            UpdateGameModeOptions();

            UpdatePlayerPausedOptions();
        }

        #region Animator Methods

        private void InitializeAnimatorOptions()
        {
            if (useAnimatorOptions == false) return;

            animatorOptions.myAnimator = GetComponent<Animator>();

            animatorOptions.childAnimators = GetComponentsInChildren<Animator>();
        }

        private void UpdateAnimatorOptions()
        {
            if (useAnimatorOptions == false
                || gameObjectInfo == null) return;

            if (UFE.isPaused() == false)
            {
                if (animatorOptions.myAnimator != null)
                {
                    animatorOptions.myAnimator.enabled = true;

                    animatorOptions.myAnimator.speed = (float)UFE.timeScale;
                }

                int length = animatorOptions.childAnimators.Length;
                for (int i = 0; i < length; i++)
                {
                    if (animatorOptions.childAnimators[i] == null) continue;

                    animatorOptions.childAnimators[i].enabled = true;

                    animatorOptions.childAnimators[i].speed = (float)UFE.timeScale;
                }
            }
            else
            {
                if (animatorOptions.myAnimator != null)
                {
                    animatorOptions.myAnimator.enabled = false;
                }

                int length = animatorOptions.childAnimators.Length;
                for (int i = 0; i < length; i++)
                {
                    if (animatorOptions.childAnimators[i] == null) continue;

                    animatorOptions.childAnimators[i].enabled = false;
                }
            }
        }

        #endregion

        #region Particle System Methods

        private void InitializeParticleSystemOptions()
        {
            if (useParticleSystemOptions == false) return;

            particleSystemOptions.myParticleSystem = GetComponent<ParticleSystem>();

            particleSystemOptions.myParticleSystemRenderer = particleSystemOptions.myParticleSystem.GetComponent<ParticleSystemRenderer>();

            particleSystemOptions.childParticleSystems = GetComponentsInChildren<ParticleSystem>();

            int length = particleSystemOptions.childParticleSystems.Length;
            particleSystemOptions.childParticleSystemRenderers = new ParticleSystemRenderer[length];
            for (int i = 0; i < length; i++)
            {
                if (particleSystemOptions.childParticleSystems[i] == null) continue;

                particleSystemOptions.childParticleSystemRenderers[i] = particleSystemOptions.childParticleSystems[i].GetComponent<ParticleSystemRenderer>();
            }
        }

        private void UpdateParticleSystemOptions()
        {
            if (useParticleSystemOptions == false
                || gameObjectInfo == null) return;

            if (particleSystemOptions.myParticleSystem != null
                && particleSystemOptions.disableGameObjectIfNotAlive == true
                && particleSystemOptions.myParticleSystem.IsAlive() == false)
            {
                this.gameObject.SetActive(false);
            }

            if (particleSystemOptions.myParticleSystem != null)
            {
                var myPS = particleSystemOptions.myParticleSystem.main;
                myPS.simulationSpeed = (float)UFE.timeScale;
            }

            int length = particleSystemOptions.childParticleSystems.Length;
            for (int i = 0; i < length; i++)
            {
                if (particleSystemOptions.childParticleSystems[i] == null) continue;

                var childPS = particleSystemOptions.childParticleSystems[i].main;
                childPS.simulationSpeed = (float)UFE.timeScale;
            }

            switch (gameObjectInfo.orderInLayerMode)
            {
                case UFE2FTEGameObjectInfo.OrderInLayerMode.Infront:
                    if (particleSystemOptions.myParticleSystemRenderer != null)
                    {
                        particleSystemOptions.myParticleSystemRenderer.sortingOrder = gameObjectInfo.orderInLayerInfront;
                    }

                    int length1 = particleSystemOptions.childParticleSystemRenderers.Length;
                    for (int i = 0; i < length1; i++)
                    {
                        if (particleSystemOptions.childParticleSystemRenderers == null) continue;

                        particleSystemOptions.childParticleSystemRenderers[i].sortingOrder = gameObjectInfo.orderInLayerInfront;
                    }
                    break;

                case UFE2FTEGameObjectInfo.OrderInLayerMode.Behind:
                    if (particleSystemOptions.myParticleSystemRenderer != null)
                    {
                        particleSystemOptions.myParticleSystemRenderer.sortingOrder = gameObjectInfo.orderInLayerBehind;
                    }

                    int length2 = particleSystemOptions.childParticleSystemRenderers.Length;
                    for (int i = 0; i < length2; i++)
                    {
                        if (particleSystemOptions.childParticleSystemRenderers == null) continue;

                        particleSystemOptions.childParticleSystemRenderers[i].sortingOrder = gameObjectInfo.orderInLayerBehind;
                    }
                    break;

                case UFE2FTEGameObjectInfo.OrderInLayerMode.Custom:
                    if (particleSystemOptions.myParticleSystemRenderer != null)
                    {
                        particleSystemOptions.myParticleSystemRenderer.sortingOrder = gameObjectInfo.orderInLayerCustom;
                    }

                    int length3 = particleSystemOptions.childParticleSystemRenderers.Length;
                    for (int i = 0; i < length3; i++)
                    {
                        if (particleSystemOptions.childParticleSystemRenderers == null) continue;

                        particleSystemOptions.childParticleSystemRenderers[i].sortingOrder = gameObjectInfo.orderInLayerCustom;
                    }
                    break;
            }
        }

        #endregion

        #region Sprite Renderer Methods

        private void InitializeSpriteRendererOptions()
        {
            if (useSpriteRendererOptions == false) return;

            spriteRendererOptions.mySpriteRenderer = GetComponent<SpriteRenderer>();

            spriteRendererOptions.childSpriteRenderers = GetComponentsInChildren<SpriteRenderer>();
        }
        
        private void UpdateSpriteRendererOptions()
        {
            if (useSpriteRendererOptions == false
                || gameObjectInfo == null) return;

            switch (gameObjectInfo.orderInLayerMode)
            {
                case UFE2FTEGameObjectInfo.OrderInLayerMode.Infront:
                    if (spriteRendererOptions.mySpriteRenderer != null)
                    {
                        spriteRendererOptions.mySpriteRenderer.sortingOrder = gameObjectInfo.orderInLayerInfront;
                    }

                    int length = spriteRendererOptions.childSpriteRenderers.Length;
                    for (int i = 0; i < length; i++)
                    {
                        if (spriteRendererOptions.childSpriteRenderers[i] == null) continue;

                        spriteRendererOptions.childSpriteRenderers[i].sortingOrder = gameObjectInfo.orderInLayerInfront;
                    }
                    break;

                case UFE2FTEGameObjectInfo.OrderInLayerMode.Behind:
                    if (spriteRendererOptions.mySpriteRenderer != null)
                    {
                        spriteRendererOptions.mySpriteRenderer.sortingOrder = gameObjectInfo.orderInLayerBehind;
                    }

                    int length1 = spriteRendererOptions.childSpriteRenderers.Length;
                    for (int i = 0; i < length1; i++)
                    {
                        if (spriteRendererOptions.childSpriteRenderers[i] == null) continue;

                        spriteRendererOptions.childSpriteRenderers[i].sortingOrder = gameObjectInfo.orderInLayerBehind;                  
                    }
                    break;

                case UFE2FTEGameObjectInfo.OrderInLayerMode.Custom:
                    if (spriteRendererOptions.mySpriteRenderer != null)
                    {
                        spriteRendererOptions.mySpriteRenderer.sortingOrder = gameObjectInfo.orderInLayerCustom;
                    }

                    int length2 = spriteRendererOptions.childSpriteRenderers.Length;
                    for (int i = 0; i < length2; i++)
                    {
                        if (spriteRendererOptions.childSpriteRenderers[i] == null) continue;

                        spriteRendererOptions.childSpriteRenderers[i].sortingOrder = gameObjectInfo.orderInLayerCustom;                    
                    }
                    break;
            }
        }

        #endregion

        #region Combat Stance Methods

        private void UpdateCombatStanceOptions()
        {
            if (useCombatStanceOptions == false
                || myControlsScript == null) return;

            int length = combatStanceOptions.Length;
            for (int i = 0; i < length; i++)
            {
                int lengthA = combatStanceOptions[i].combatStances.Length;
                for (int a = 0; a < lengthA; a++)
                {
                    if (myControlsScript.currentCombatStance != combatStanceOptions[i].combatStances[a]) continue;

                    int lengthB = combatStanceOptions[i].gameObjects.Length;
                    for (int b = 0; b < lengthB; b++)
                    {
                        if (combatStanceOptions[i].gameObjects[b] == null) continue;

                        if (combatStanceOptions[i].gameObjectAction == GameObjectAction.Disable)
                        {
                            combatStanceOptions[i].gameObjects[b].SetActive(false);
                        }
                        else if (combatStanceOptions[i].gameObjectAction == GameObjectAction.Enable)
                        {
                            combatStanceOptions[i].gameObjects[b].SetActive(true);
                        }
                    }
                }
            }
        }

        #endregion

        #region Game Mode Methods

        private void UpdateGameModeOptions()
        {
            if (useGameModeOptions == false) return;

            int length = gameModeOptions.Length;
            for (int i = 0; i < length; i++)
            {
                int lengthA = gameModeOptions[i].gameModes.Length;
                for (int a = 0; a < lengthA; a++)
                {
                    if (UFE.gameMode != gameModeOptions[i].gameModes[a]) continue;

                    int lengthB = gameModeOptions[i].gameObjects.Length;
                    for (int b = 0; b < lengthB; b++)
                    {
                        if (gameModeOptions[i].gameObjects[b] == null) continue;

                        if (gameModeOptions[i].gameObjectAction == GameObjectAction.Disable)
                        {
                            gameModeOptions[i].gameObjects[b].SetActive(false);
                        }
                        else if (gameModeOptions[i].gameObjectAction == GameObjectAction.Enable)
                        {
                            gameModeOptions[i].gameObjects[b].SetActive(true);
                        }
                    }
                }
            }
        }

        #endregion

        #region Player Paused Methods

        private void UpdatePlayerPausedOptions()
        {
            if (usePlayerPausedOptions == false) return;

            if (UFE2FTEPlayerPausedManager.playerPaused == UFE2FTEPlayerPausedManager.PlayerPaused.Player1Paused)
            {
                int length = player1PausedOptions.Length;
                for (int i = 0; i < length; i++)
                {
                    int lengthA = player1PausedOptions[i].gameObjects.Length;
                    for (int a = 0; a < lengthA; a++)
                    {
                        if (player1PausedOptions[i].gameObjects[a] == null) continue;

                        if (player1PausedOptions[i].gameObjectAction == GameObjectAction.Disable)
                        {
                            player1PausedOptions[i].gameObjects[a].SetActive(false);
                        }
                        else if (player1PausedOptions[i].gameObjectAction == GameObjectAction.Enable)
                        {
                            player1PausedOptions[i].gameObjects[a].SetActive(true);
                        }
                    }
                }
            }
            else if (UFE2FTEPlayerPausedManager.playerPaused == UFE2FTEPlayerPausedManager.PlayerPaused.Player2Paused)
            {
                int length = player2PausedOptions.Length;
                for (int i = 0; i < length; i++)
                {
                    int lengthA = player2PausedOptions[i].gameObjects.Length;
                    for (int a = 0; a < lengthA; a++)
                    {
                        if (player2PausedOptions[i].gameObjects[a] == null) continue;

                        if (player2PausedOptions[i].gameObjectAction == GameObjectAction.Disable)
                        {
                            player2PausedOptions[i].gameObjects[a].SetActive(false);
                        }
                        else if (player2PausedOptions[i].gameObjectAction == GameObjectAction.Enable)
                        {
                            player2PausedOptions[i].gameObjects[a].SetActive(true);
                        }
                    }
                }
            }
        }

        #endregion
    }
}

Share

Thumbs up +2 Thumbs down

Re: Pause Everything On Pause?

@FreedTerror. Can I put this is a character's prefab? I just have too many particles to put this script in each and every one of them.

Share

Thumbs up Thumbs down

Re: Pause Everything On Pause?

Place the script on the root prefab.
The script will get all child particle systems.

Share

Thumbs up Thumbs down