Hello, guys.
In this video, I want to talk about execution order.
Something you should know.
I actually made this very same video just months ago on the very same topic for my another course.
So if you don't mind, let's watch that video together because it has same information.
And I don't really see the point of recording same video again.
Know, I hope you can forgive me that.
Let's watch the video here.
Hello, my name is Alex, and in this video I want to talk about execution order in unity.
Why we need to know about it.
I'm going to tell you in a second.
For now, just watch and absorb information.
All right.
I'm going to open my player script.
And you can see here there is an update and a start method.
These two functions called, by the way, function and method is the same.
All right.
So sometimes I'm going to use that word, sometimes another, but it doesn't matter.
It's the same.
Now start called once before the update.
Once before the first update an update called once per frame.
So if your game is 60 frames per second, then update will be called 60 times per second.
I have already debug line in the start method and I'm going to make one more in the update.
Update is called.
Can I save it?
Now, check this.
When I play my game.
The start was called only once.
An update is called all the time.
That's why we do movement and check for inputs in the update because we need to check if there is input
all the time.
Right?
Every frame.
We need to make sure if somebody pressed or did not press the button, but start is called once and
it can be used for different stuff like assigning default value, assigning components.
And we're going to do all of that later.
But now I want to tell you about a few more methods that are in the execution order.
There is a wake function, a wake function called once when game is initialized or when game object
is enabled.
I'm going to do debug log.
Awake was cold.
And back in unity, I'm going to duplicate my player and switch it off.
Because it has players script here and here.
Now, look.
I played a game a week, was called once.
Start was called once and update is called all the time.
Now if I switch off, this one function is not called anymore and I'm going to switch off another one
that I duplicated.
Check this out.
Awake was cold.
Start was cold.
Now if I switch it off and switch on the first one.
There will be no wake or start method because, as I said, it called only once at the beginning.
There is one more and it is called fixed update.
It happens before the update.
Fixed update.
Debug log.
Fixed.
Update.
Ace hold.
Is it?
The right sentence is called.
Uh, who cares?
All right.
Now you can see that fixed update is called all the time as well, but not so often as an update.
Why is that?
Because fixed update has certain amount of steps.
I would say we can go to edit project settings, open the time, and here you can see fixed timestamp
0.02.
So at the moment, fixed update called 50 times per second.
If I would do zero 0 to 0 two.
Yes.
Clear.
Now you can see it's called five times per second.
Why?
It's.
Yeah.
Okay now?
Yeah.
0.2.
And now it's called five times per second.
Slower.
Much slower.
If I said 0.5 would be called two times per second and so on.
Why we need this?
There is a reason why we need this look fixed.
Update Mostly used for coding and check in physics and movement because you don't want your movement
to be faster than you need it to be.
Like there was a case in Fallout 76, for example, when if piece of the player was low, he moved slowly.
But when space is higher, he moved faster and he attacked faster.
I don't think it's important for this game, but anyway, you should know this information, right?
Actually, execution in order is much bigger and more complex than I showed you is much more than awake.
Start fixed update and update.
You can find it easily in Google and just type unity execution order right here.
And the first link you can see how big it is.
Wake on enable reset start fixed update.
We talked about then some more than update, then some more then later update and some more and application
quit disable destroyed.
Right.
And at some point you'll know it and you'll need to know it.
But for now, as a beginner, you don't have to use your phone right?
Or computer you don't know how does it work, but you can use it.
It's the same here.
You're not sure how does it work, but you can use it and it's totally fine because we here talking
about making a game, not a sandwich.
It's a really big case.
You know, not everybody can make a game.
Not everybody can do it fast.
Most of the people won't even finish making a game.
And in fact, most of the people even want finish a course where I'm showing how to make a game.
Right.
So you cannot beat it overnight.
It's fine.
Take your time.
And one day I promise to you you'll be there.
Yeah.
So I agree with everything I said before months ago, and I feel like my voice is a bit sleepy on that
video.
Maybe I did record it in the morning.
Anyway, now you know a bit more.
And let's move to next video.