1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:03,000
In this video, I want to talk about execution order.

3
00:00:03,000 --> 00:00:04,000
Something you should know.

4
00:00:04,000 --> 00:00:11,000
I actually made this very same video just months ago on the very same topic for my another course.

5
00:00:11,000 --> 00:00:15,000
So if you don't mind, let's watch that video together because it has same information.

6
00:00:15,000 --> 00:00:18,000
And I don't really see the point of recording same video again.

7
00:00:19,000 --> 00:00:20,000
Know, I hope you can forgive me that.

8
00:00:21,000 --> 00:00:24,000
Let's watch the video here.

9
00:00:27,000 --> 00:00:33,000
Hello, my name is Alex, and in this video I want to talk about execution order in unity.

10
00:00:33,000 --> 00:00:34,000
Why we need to know about it.

11
00:00:34,000 --> 00:00:36,000
I'm going to tell you in a second.

12
00:00:36,000 --> 00:00:38,000
For now, just watch and absorb information.

13
00:00:38,000 --> 00:00:39,000
All right.

14
00:00:39,000 --> 00:00:40,000
I'm going to open my player script.

15
00:00:40,000 --> 00:00:44,000
And you can see here there is an update and a start method.

16
00:00:45,000 --> 00:00:49,000
These two functions called, by the way, function and method is the same.

17
00:00:49,000 --> 00:00:50,000
All right.

18
00:00:50,000 --> 00:00:54,000
So sometimes I'm going to use that word, sometimes another, but it doesn't matter.

19
00:00:54,000 --> 00:00:55,000
It's the same.

20
00:00:55,000 --> 00:00:59,000
Now start called once before the update.

21
00:00:59,000 --> 00:01:05,000
Once before the first update an update called once per frame.

22
00:01:05,000 --> 00:01:12,000
So if your game is 60 frames per second, then update will be called 60 times per second.

23
00:01:12,000 --> 00:01:17,000
I have already debug line in the start method and I'm going to make one more in the update.

24
00:01:20,000 --> 00:01:22,000
Update is called.

25
00:01:23,000 --> 00:01:24,000
Can I save it?

26
00:01:24,000 --> 00:01:25,000
Now, check this.

27
00:01:26,000 --> 00:01:27,000
When I play my game.

28
00:01:27,000 --> 00:01:31,000
The start was called only once.

29
00:01:31,000 --> 00:01:34,000
An update is called all the time.

30
00:01:34,000 --> 00:01:41,000
That's why we do movement and check for inputs in the update because we need to check if there is input

31
00:01:41,000 --> 00:01:42,000
all the time.

32
00:01:42,000 --> 00:01:42,000
Right?

33
00:01:42,000 --> 00:01:43,000
Every frame.

34
00:01:43,000 --> 00:01:50,000
We need to make sure if somebody pressed or did not press the button, but start is called once and

35
00:01:50,000 --> 00:01:55,000
it can be used for different stuff like assigning default value, assigning components.

36
00:01:55,000 --> 00:01:56,000
And we're going to do all of that later.

37
00:01:56,000 --> 00:02:00,000
But now I want to tell you about a few more methods that are in the execution order.

38
00:02:00,000 --> 00:02:11,000
There is a wake function, a wake function called once when game is initialized or when game object

39
00:02:11,000 --> 00:02:12,000
is enabled.

40
00:02:12,000 --> 00:02:14,000
I'm going to do debug log.

41
00:02:15,000 --> 00:02:17,000
Awake was cold.

42
00:02:20,000 --> 00:02:25,000
And back in unity, I'm going to duplicate my player and switch it off.

43
00:02:26,000 --> 00:02:29,000
Because it has players script here and here.

44
00:02:30,000 --> 00:02:31,000
Now, look.

45
00:02:33,000 --> 00:02:36,000
I played a game a week, was called once.

46
00:02:36,000 --> 00:02:40,000
Start was called once and update is called all the time.

47
00:02:40,000 --> 00:02:47,000
Now if I switch off, this one function is not called anymore and I'm going to switch off another one

48
00:02:47,000 --> 00:02:49,000
that I duplicated.

49
00:02:50,000 --> 00:02:51,000
Check this out.

50
00:02:51,000 --> 00:02:52,000
Awake was cold.

51
00:02:52,000 --> 00:02:54,000
Start was cold.

52
00:02:56,000 --> 00:02:59,000
Now if I switch it off and switch on the first one.

53
00:03:00,000 --> 00:03:07,000
There will be no wake or start method because, as I said, it called only once at the beginning.

54
00:03:07,000 --> 00:03:11,000
There is one more and it is called fixed update.

55
00:03:13,000 --> 00:03:15,000
It happens before the update.

56
00:03:15,000 --> 00:03:17,000
Fixed update.

57
00:03:18,000 --> 00:03:20,000
Debug log.

58
00:03:21,000 --> 00:03:22,000
Fixed.

59
00:03:23,000 --> 00:03:24,000
Update.

60
00:03:24,000 --> 00:03:25,000
Ace hold.

61
00:03:29,000 --> 00:03:29,000
Is it?

62
00:03:29,000 --> 00:03:31,000
The right sentence is called.

63
00:03:32,000 --> 00:03:34,000
Uh, who cares?

64
00:03:34,000 --> 00:03:35,000
All right.

65
00:03:40,000 --> 00:03:48,000
Now you can see that fixed update is called all the time as well, but not so often as an update.

66
00:03:49,000 --> 00:03:49,000
Why is that?

67
00:03:49,000 --> 00:03:53,000
Because fixed update has certain amount of steps.

68
00:03:53,000 --> 00:04:02,000
I would say we can go to edit project settings, open the time, and here you can see fixed timestamp

69
00:04:02,000 --> 00:04:03,000
0.02.

70
00:04:03,000 --> 00:04:08,000
So at the moment, fixed update called 50 times per second.

71
00:04:08,000 --> 00:04:13,000
If I would do zero 0 to 0 two.

72
00:04:13,000 --> 00:04:14,000
Yes.

73
00:04:17,000 --> 00:04:18,000
Clear.

74
00:04:18,000 --> 00:04:22,000
Now you can see it's called five times per second.

75
00:04:22,000 --> 00:04:22,000
Why?

76
00:04:22,000 --> 00:04:23,000
It's.

77
00:04:24,000 --> 00:04:25,000
Yeah.

78
00:04:27,000 --> 00:04:27,000
Okay now?

79
00:04:27,000 --> 00:04:28,000
Yeah.

80
00:04:28,000 --> 00:04:29,000
0.2.

81
00:04:29,000 --> 00:04:32,000
And now it's called five times per second.

82
00:04:32,000 --> 00:04:33,000
Slower.

83
00:04:33,000 --> 00:04:34,000
Much slower.

84
00:04:34,000 --> 00:04:41,000
If I said 0.5 would be called two times per second and so on.

85
00:04:41,000 --> 00:04:42,000
Why we need this?

86
00:04:42,000 --> 00:04:45,000
There is a reason why we need this look fixed.

87
00:04:45,000 --> 00:04:51,000
Update Mostly used for coding and check in physics and movement because you don't want your movement

88
00:04:51,000 --> 00:04:53,000
to be faster than you need it to be.

89
00:04:53,000 --> 00:05:02,000
Like there was a case in Fallout 76, for example, when if piece of the player was low, he moved slowly.

90
00:05:02,000 --> 00:05:07,000
But when space is higher, he moved faster and he attacked faster.

91
00:05:07,000 --> 00:05:14,000
I don't think it's important for this game, but anyway, you should know this information, right?

92
00:05:15,000 --> 00:05:21,000
Actually, execution in order is much bigger and more complex than I showed you is much more than awake.

93
00:05:21,000 --> 00:05:23,000
Start fixed update and update.

94
00:05:23,000 --> 00:05:30,000
You can find it easily in Google and just type unity execution order right here.

95
00:05:31,000 --> 00:05:33,000
And the first link you can see how big it is.

96
00:05:34,000 --> 00:05:36,000
Wake on enable reset start fixed update.

97
00:05:36,000 --> 00:05:46,000
We talked about then some more than update, then some more then later update and some more and application

98
00:05:46,000 --> 00:05:48,000
quit disable destroyed.

99
00:05:48,000 --> 00:05:48,000
Right.

100
00:05:48,000 --> 00:05:52,000
And at some point you'll know it and you'll need to know it.

101
00:05:52,000 --> 00:05:55,000
But for now, as a beginner, you don't have to use your phone right?

102
00:05:55,000 --> 00:05:59,000
Or computer you don't know how does it work, but you can use it.

103
00:06:00,000 --> 00:06:01,000
It's the same here.

104
00:06:01,000 --> 00:06:07,000
You're not sure how does it work, but you can use it and it's totally fine because we here talking

105
00:06:07,000 --> 00:06:09,000
about making a game, not a sandwich.

106
00:06:09,000 --> 00:06:11,000
It's a really big case.

107
00:06:11,000 --> 00:06:13,000
You know, not everybody can make a game.

108
00:06:13,000 --> 00:06:15,000
Not everybody can do it fast.

109
00:06:15,000 --> 00:06:18,000
Most of the people won't even finish making a game.

110
00:06:18,000 --> 00:06:24,000
And in fact, most of the people even want finish a course where I'm showing how to make a game.

111
00:06:24,000 --> 00:06:24,000
Right.

112
00:06:24,000 --> 00:06:27,000
So you cannot beat it overnight.

113
00:06:27,000 --> 00:06:28,000
It's fine.

114
00:06:29,000 --> 00:06:29,000
Take your time.

115
00:06:29,000 --> 00:06:32,000
And one day I promise to you you'll be there.

116
00:06:32,000 --> 00:06:33,000
Yeah.

117
00:06:33,000 --> 00:06:39,000
So I agree with everything I said before months ago, and I feel like my voice is a bit sleepy on that

118
00:06:39,000 --> 00:06:39,000
video.

119
00:06:40,000 --> 00:06:41,000
Maybe I did record it in the morning.

120
00:06:42,000 --> 00:06:44,000
Anyway, now you know a bit more.

121
00:06:44,000 --> 00:06:45,000
And let's move to next video.

