The right way to pause a game in Unity

preview_player
Показать описание

Learn how to pause a game in Unity, the right way, using time scale.

00:00 Intro
01:13 How to use time scale in Unity
02:15 How time scale works
03:38 What does & doesn't get paused
05:27 Prevent objects from being paused (using Unscaled Time)
06:36 How to pause audio
07:29 How to prevent input when pausing the game
08:37 Outro

You'll learn how to use time scale to pause and unpause your game, what is and isn't affected by a timescale pause and how to manage systems that don't work how you might expect when pausing the game in this way.

Outro music: New Year by Bad Snacks

Рекомендации по теме
Комментарии
Автор

I just recently added a pause option to my game for the first time and I also did it by setting Time.timeScale = 0 and then having a static bool that kept track of if the game was paused or not. I find doing it this way is pretty easy and intuitive. Also did not know that you can just pause all AudioSources just from one line of code lol, thanks for bringing this up!

MyPing
Автор

The quality of this video is insane, very well scripted and explained, great editing and the information in it is really different from what would you expect from similar videos explaining the same topic, when the video said: "the right way" something in my head told me: this guy knows what he is doing👏
really great content, I feel that we lost brackeys, but we are going to have this guy.
good luck man, really great content.

zaidmermam
Автор

This was really useful for me! Please make more videos like this about lesser-known Unity tips and tricks.

thefearlesspredators.
Автор

Never quit uploading content, your video quality is really a rare gem to find in the Unity tutorial world these days. This video truly felt like being in a university actually learning something. Keep up the great work.

dykycoend
Автор

This is one of the best tutorials I have seen so far. Easy to understand and concise. Thanks a lot!

indieforger
Автор

Hey, dude, you won't believe the immense help you provided me with! I can't stress enough how grateful I am. Remember when you mentioned that crucial detail at 2:08? Well, I was in the middle of creating the Pause Menu for my game and encountered a perplexing issue. Whenever I transitioned back to the Game Scene from Main Menu, the game froze completely. I tried everything, even deep profiling, but couldn't make any sense of it. All I could observe was that the 'asyncoperationtocomplete()' function was taking an unusually long time. However, thanks to your advice, I decided to set the timescale to 1 before exiting the Game scene, and voila! It miraculously worked! I cannot thank you enough for your invaluable assistance!💕💕

Ashwin_
Автор

I read your blog about pause a game.Amazing blogpost to answer almost every question.Thank you

saitakman
Автор

This is a good quality video that solved my problem. Great job !

alexandrusirbu
Автор

Amazing video, love how you explain everything and show different examples. Now to watch all your other vids.

mattsithknight
Автор

Need to pause the game whenever interacting with npc:s to actually be able to use mouse to answer NPC. Helpful tutorial, thank you.

BlinkersGameDev
Автор

about 7:30 i have a pause menu but if pause and click on resume the cursor get deactivated so im not able too click on button on pause how to fix?i also use standard assets third person controller my pause menu script is : using UnityEngine;
using UnityEngine.SceneManagement;
using Unity.Netcode;

public class PauseMenu : MonoBehaviour
{
public static bool Paused = false;
public GameObject PauseMenuCanvas;

void Start()
{
Time.timeScale = 1f;

}

void Update()
{
if
{
if (Paused)
ResumeGame();
else
PauseGame();
}
}

void PauseGame()
{

Time.timeScale = 0f;
Paused = true;
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}

public void ResumeGame()
{

Time.timeScale = 1f;
Paused = false;
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}

public void LeaveSession()
{
if ||

else if


Time.timeScale = 1f;
Paused = false;

}
}

bonse
Автор

I had just had a similar problem and this is the video that I would have liked to see first.
It has a very good quality, it focuses on explaining the deep instead of the superficial and about the article, the article is INSANE, well explained and looks great.
you gained a spanish speaking subscriber

JimSegovia
Автор

Really well explained. You deserve a lot more subscribers!

TopShelfCookieJar
Автор

Here before 1000 subs.
Great video! Editing was simple but good. Explanation was good.

johnthesilverwing
Автор

This was really helpful. I've traditionally just been using a GameState object that sends out a 'GamePaused' event, and having all of the objects that need to respond to that and set their own 'isPaused' state accordingly, but things with Physics of course don't follow that so that's been a challenge. I totally didn't know you could do this, this helps so much, thank you! Love your blog too!

svenbtb
Автор

My saviour! I didn't know about the unscaled time before and was actually looking for a way to keep UI animations to keep working during a pause.

LoldemortII
Автор

I just found your channel, I love your content and your way of explaining things. I just watched the Unity events Video and was impressed so I supped and started watching your other videos. continue with this quality and you'll have 500k sups in no time. good luck!

yasseraltamimi
Автор

I recently had issues in my game with using TimeScale at 0 to pause, as it can potentially stop other scripts in the game midway through execution.

The way I got around this was to have the pause button set a bool, then run the check to set the Timescale to 0 in LateUpdate() as this is more likely to run once everything else is finished in that frame.

joshduffety-wong
Автор

I’m currently working on a Halo VR game and pausing is turning out to be a pain in the arse, this video helped me so much! Cheers man!

firingpin
Автор

Thanks for this. It helped me solve the problem of letting a user type into an input field and not have the navigation actions take place if you typed an E or other nav key.

jeff_holmes
welcome to shbcf.ru