Pause in Unity WITHOUT Timescale

Pause in Unity WITHOUT Timescale

James Makes Games

2 года назад

117,177 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@JamesMakesGamesYT
@JamesMakesGamesYT - 23.12.2021 16:43

How do you normally pause your game in Unity? Will you try using events in the future?

Ответить
@shinryusaiha
@shinryusaiha - 22.01.2024 11:37

To the nay sayers in comments, this is how you are supposed to pause. Dont be lazy and sloppy take your time to make your game right. Events are efficient and performant and this removes any bugs with pausing from the various other lazy methods.

Ответить
@bernardo231
@bernardo231 - 17.12.2023 02:19

"find a script that will be affected by pausing" - like almost all of them?
Do I need to put all this amount of code in every script that is affected by pause?

Ответить
@reyou7
@reyou7 - 07.12.2023 07:32

You are actually teaching here how to create a singleton and use delegates and events. This is not a tutorial of "better pausing technique" in Unity.

Ответить
@Souloutions
@Souloutions - 02.12.2023 04:25

Doesn't work, tried to make it work with many and many changes but nothing

Ответить
@MangoBoxYT
@MangoBoxYT - 11.11.2023 19:12

Assets\PlayerMovement1.cs(6,14): error CS0101: The namespace '<global namespace>' already contains a definition for 'PlayerMovement'
Assets\InputManager.cs(8,13): error CS0246: The type or namespace name 'Controls' could not be found (are you missing a using directive or an assembly reference?)
Assets\PlayerMovement1.cs(11,10): error CS0111: Type 'PlayerMovement' already defines a member called 'Awake' with the same parameter types

3 Errors but What is these mean?!?!
I've just got some of these codes/scripts on the description.

Ответить
@byram_brt
@byram_brt - 30.10.2023 20:12

code link cant open :(

Ответить
@byram_brt
@byram_brt - 30.10.2023 20:11

i cant reach code links

Ответить
@Seshua87
@Seshua87 - 01.10.2023 00:55

I thought I was watching a tutorial
Little did I know it was actually a speedrun.

Ответить
@samisalama3033
@samisalama3033 - 02.08.2023 18:38

can it be used to slow down specific gameobjects?

Ответить
@emilhdov3350
@emilhdov3350 - 21.07.2023 08:56

Hi bro, I just ask one question. What the fuck are you doing?!

Ответить
@ssalovaa
@ssalovaa - 20.07.2023 22:08

what about things that can't be controlled this way, such as physics?

Ответить
@bimbomariano898
@bimbomariano898 - 19.07.2023 03:48

wayyy more complex.....

Ответить
@overcookedwalrus4482
@overcookedwalrus4482 - 03.07.2023 01:24

Right, this is so much more simple and less convoluted... why didn't I think of this?

Ответить
@somegamer7958
@somegamer7958 - 16.06.2023 10:05

this is insane lol....I mean this might work for some tiny games, but now you have issues where you're going to have to pause/unpause animations manually, you'll have to freeze/unfreeze physics...it's just an insane amount of work. I'll just tolerate animations resetting themselves

Ответить
@kupcuk
@kupcuk - 18.04.2023 18:15

does this require a subjective pause for each class to listen to pause state or am I missing sth? what happens when state change flag is raised? this looks like complicating things through observer pattern with no actual pause method.

Ответить
@ajononikostudio
@ajononikostudio - 01.04.2023 02:26

Your code doesn't work, triple checked everything, escape key does nothing with the correct pause controller script attached to the gamemanager object in the scene. Unfortunately, time was wasted.

Ответить
@TheLunarah
@TheLunarah - 23.03.2023 16:14

Why is there that enable variable on player script?

Ответить
@ErrorUncertainty
@ErrorUncertainty - 21.01.2023 19:34

I can see how this would be a good way to handle where in code to set timescale to 0, but I really don't understand how it could replace timescale. How would this work with dozens / hundreds of different physics objects across a game? Would they all require individual code to be told to pause? What about just simple 2d rigidbody objects with gravity - would we have to turn off gravity for each one individually?

Ответить
@junaidywijaya
@junaidywijaya - 08.12.2022 22:00

Many people seems angry about this, but i have an opinion that this could be useful, yes many people hate the Singleton but you could replace it, and if you ever played the game called "Sniper elite" You know that there is a lot of camera cinematic shot and slow motion, you could take advantage of disabling player control while manipulating timescale to create slow motion effect

Ответить
@dibaterman
@dibaterman - 10.11.2022 21:44

I thought the way to avoid Animator issues was to just set those to unscaled time in the Animator. I mean this also can crop up other issues. I mean this is elegant but I can see some issues trying to apply it to the system I have.

For example in my case I have a weapon controller that likes to know who owns the controller, it can get this one of two ways, 1 from the player or 2 from the weapon it is controlling. If there is no player it will look for a weapon(disabled via this method), but if there is no weapon or player we have an issue. So there are a ton of ways to work around this for example making the weapon controller look for the asset similar to the weapon it cared about but it just seems like a lot when the alternative is a check box in the animator.

Anyway nice video.

Ответить
@Nekotico
@Nekotico - 28.08.2022 08:39

how can i do this except animating a camera and let a character do a special move while everithing else is freeze?

Ответить
@fabriperoconalgomasytodojunto
@fabriperoconalgomasytodojunto - 11.08.2022 18:05

I just set the speed of the player to a constant 0 so he can't move XD

Ответить
@watercat1248
@watercat1248 - 08.08.2022 01:06

this pause system you mention in the video Sounds completed and I don't think it's the best paused system for my game

1. in my I have a lot of different codes I have physics audio animation ECT and i personally don't want to create specific event for each off my code or section my game have this sounds like nightmare to create
2. with using time scale the handle all those stuff and I only have to create pause acception spefic cases

like for example let's say that I have button that appears and disappear a object the time scale don't change that however it's very easy to use time scale and just create acception in specific Case

Ответить
@Xfushion2
@Xfushion2 - 25.07.2022 06:31

IMO this is too redundant, you are basically creating a state machine that every single object you want to be afected by pause needs to subscribe to.
For those how don't know unity has actually unscaledTime that means that by using it instead of time the code will run in real seconds and not Unity's time.
For example a coroutine with WaitForSeconds won't work with timescale = 0 but WaitForSecondsRealtime will.
this applies to animations, they have a parameter called update mode that can be set to unscaled time and now the animations will always run even if timescale = 0;
TL;DR just use timescale = 0 and use unscaledTime in your code for the objects/behaviors you don't want to be affected by pause

Ответить
@lordpapkin7540
@lordpapkin7540 - 22.07.2022 13:30

So complex in just 2 minutes, and it feels sooo clean, amazing work

Ответить
@reglan_dev
@reglan_dev - 11.07.2022 11:15

its like wtf, just a messy garbage. You overcomplicated such a simple concept

Ответить
@ItsBixbyBoo
@ItsBixbyBoo - 20.06.2022 22:33

can you link the code?

Ответить
@heribertosalais4678
@heribertosalais4678 - 06.06.2022 20:16

What is the function of GameStateActiveController Sritpt on the Pause Screen? The code wasnt displayed on the video

Ответить
@pt8306
@pt8306 - 03.06.2022 09:13

Instead of handling pausing per-object manually every time, create an abstract class that inherits from MonoBehaviour called PausableBehaviour. Give it 2 virtual, empty functions called UpdateUnpaused and UpdatePaused. Then, override the Update function (and make it final) to check for a local boolean isPaused, which is set to true/false based on the pause and unpause events. If isPaused is set, make Update call UpdatePaused, else call UpdateUnpaused. Then, make your game objects inherit off PausableBahviour rather than MonoBehaviour, and you will automatically have access to override the PausedUpdate and UnpausedUpdate functions for different functionality without rewriting anything. Or, even better, don't use this terrible tutorial and make a better pause method in the first place.

Ответить
@haroldallaberg6359
@haroldallaberg6359 - 27.05.2022 15:09

CODE
Coming Soon

bruh really? it's been over a year!

Ответить
@marscaleb
@marscaleb - 18.05.2022 06:17

Okay, I actually wound up copying this because I wound up having a gameplay element where I needed to pause only certain characters, and this served as a useful starting point.
I still use the classic "timescale to zero" method for the normal pause because it will cover everything without having to think about it, but this is useful for selectively pausing objects.

Ответить
@alexyz9430
@alexyz9430 - 08.02.2022 05:38

Disliked, apple pie

Ответить
@IlSharmouta
@IlSharmouta - 05.02.2022 23:33

I'm curious whether this is just something you learned/came up with and are sharing theoretical benefits, or if this is actually something that you have experience with in a larger project and found these benefits to be worth it.

Ответить
@hegworks
@hegworks - 05.02.2022 10:22

This is NOT a better way than using timescale. You just had a single system in your game, Movement. In any more-developed game you will end up with lots and lots of different system and many many more classes other than PlayerMovement. Hooking each of them separately will be a nightmare and since you are using events, it will be another nightmare to debug. So, new devs, DO NOT use this method. Simply use the Timescale. More experienced devs won't need an advice, they themselves already know they should not use it.

Also, the reasons why you said using timescale to pause is bad, are not correct but this comment has already become too long.

Ответить
@jaspervandijk27
@jaspervandijk27 - 04.02.2022 12:10

timescale has more advantages, you can keep animations working, and you can make the timescale interpolate.

Ответить
@SlavicPickle
@SlavicPickle - 04.02.2022 02:39

Time.scale = 0; will always be better than this. Nice tutorial tho

Ответить
@erwinveenhoven7446
@erwinveenhoven7446 - 04.02.2022 02:30

Just use unscaled time for the things you want to keep running. That is way easier and I never had a problem with it.

Ответить
@Jamesthe1
@Jamesthe1 - 04.02.2022 00:32

Works the same for Godot. It has an option to set the time scale, but this also interferes with things you don't want paused. This is a good way to control it imho.

Ответить
@orlovskyconsultinggbr2849
@orlovskyconsultinggbr2849 - 02.02.2022 22:07

Well this is interesting, let me give some useful tipp: in order to have a structured code use empty GameObjects as sort of reference , then you can attach scripts and can establish a architecture . Depending on the scale of the game , you can save those gameobject to file system and load them as per need mode, this would allow to increase performance. Really important question: How many GameObjects should have script as component, well i always try to minimize that and attach scripts to GameObject, only if absolutely necessary, otherwise i dont attach scripts as components. Why? Well then i can easy unit test the scripts ;)

Ответить
@leonov-v
@leonov-v - 02.02.2022 21:19

Thanks a lot, very useful tip!

Ответить
@Pfaeff
@Pfaeff - 02.02.2022 20:17

How can you turn off the physics engine?

Ответить
@wangtang32000
@wangtang32000 - 02.02.2022 19:45

i like this idea. but i think i'll stick to timescale to 0 so i can manually animate specific things like the pause menu to an unscaled time.

Ответить
@bunnykill
@bunnykill - 02.02.2022 18:49

king

Ответить
@MrZtapp
@MrZtapp - 02.02.2022 11:35

Really appreciate these short very educational videos.

Ответить
@oivinf
@oivinf - 02.02.2022 05:07

Good way to give yourself a ton of extra work. If you need something (a timer, or animation) to not pause when the timescale is set to 0 there is always a way to use realtime or unscaled time. Animators, DoTween and custom scripts are all easy to do this with, without all this added complexity

Ответить
@plasticflower
@plasticflower - 01.02.2022 23:56

Wait, am I missing something? Where in the other objects like the player cube object did you actually check whether the gamestate is paused or not and alter their behaviour accordingly? Or did you just skip over that part? Just setting a variable in a singleton doesn't do anything unless all other objects are told how to behave according to how it changes. And I guess that's the reason why people use the timescale, because they notice at some point that they want to pause and timescale allows to do it without adding a parent state to all other gameobjects.

Ответить
@TheRomixERR
@TheRomixERR - 31.01.2022 19:16

Ибануцца ИГОРЬ. С десятаго раса понъял!

Ответить
@mracipayam
@mracipayam - 31.01.2022 12:54

Nice info, thanks.

Ответить