Issue with "pausing" game and respawning characters - Unity hangs/freezes

msm

New member
Hi,

Im encountering an issue when I "pause" my game (Time.timeScale = 0, UltimateCharacterLocomotion.TimeScale = 0, player inputs disabled) and characters respawning after death. Unity hangs (infinite loop perhaps?) after the character respawns during this "paused" game state.

Has anyone else encountered this?
 
I'm curious as to how your character dies/re-spawns during a pause state if the entire game freezes during the pause state?

It's also generally not good practice in Unity to set Time.timeScale to 0 during run-time, because it can cause errors exactly like this one. I would recommend you find an alternative solution, for example freezing the movement of objects similar to how you set your character's locomotion time scale to 0.

If you absolutely must set Time.timeScale = 0, then you should set it back to 1 for at least a frame or two when re-spawning the character.
 
I'm curious as to how your character dies/re-spawns during a pause state if the entire game freezes during the pause state?

It's also generally not good practice in Unity to set Time.timeScale to 0 during run-time, because it can cause errors exactly like this one. I would recommend you find an alternative solution, for example freezing the movement of objects similar to how you set your character's locomotion time scale to 0.

If you absolutely must set Time.timeScale = 0, then you should set it back to 1 for at least a frame or two when re-spawning the character.

Hi, thanks for the reply.

Im using the built-in CharacterRespawner and Health components from Opsive. Health fires the death event, Respawner is scheduling a respawn after death. As for how the Scheduler still ticks away while Time.timeScale=0, I dont know, that source code isnt provided.

This particular issue is not actually tied to Time.timeScale, but rather CharacterLocomtion.TimeScale=0. I've narrowed down to AnimatorMonitor.cs it has a couple places where it does this
while (IsInTransition()) { ...
where IsInTransition is checking for m_Animator.IsInTransition(i). It is an infinite loop when CharacterLocomotion.TimeScale is set to 0. I actually got this state change idea from another forum thread you replied in.

Is there an intended way for pausing gameplay with UCC? I've not found any documentation on it.

As for TIme.timeScale = 0, from what I've read, Time.timeScale=0 is generally the only way "pausing" gameplay in Unity is handled.
How do you handle pausing physics objects and particles and everything else if you don't set TimeScale to 0 without managing all references to these things?
 
You shouldn't actually need to set any characters' time scale to 0 if you're already setting the global time scale to 0.

Try just setting Time.timeScale to 0 and nothing else.
 
I've tried that as well, but you run into errors if for example you pause while a character is falling. You run into this error

Code:
transform.position assign attempt for 'Player' is not valid. Input position is { NaN, NaN, NaN }.
UnityEngine.Transform:set_position(Vector3)
Opsive.UltimateCharacterController.Character.CharacterLocomotion:ApplyPosition() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:1414)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:ApplyPosition() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:987)
Opsive.UltimateCharacterController.Character.CharacterLocomotion:UpdatePositionAndRotation() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:542)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:UpdatePositionAndRotation() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:825)
Opsive.UltimateCharacterController.Character.CharacterLocomotion:UpdatePositionAndRotation(Boolean) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:517)
Opsive.UltimateCharacterController.Character.CharacterLocomotion:OnAnimatorMove() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:1470)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:OnAnimatorMove() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1757)
 
Hm, it is possible to avoid this error with a check on m_MoveDirection, but the player ends up hanging in midair. I'll pass this on to Justin as a potential future update!

For now, I'd recommend a workaround solution, for example disallowing pause whilst a character is in midair, or manually handling the time scale of different objects instead of using global Time.timeScale.

edit: The mid-air issue will actually be fixed in the next version, which will hopefully be released some time this week!
 
Im targeting a local multiplayer splitcreen game, so having pause not actually pause everything could pose potential cheap tactics... Im just going to workaround it but using my own Character respawner that doesnt go through the Scheduler since it doesnt seem to honor Time.timeScale=0.
That way characters wont respawn while during this pause state and shouldnt run into the original issue.
 
Top