﻿1
00:00:04,530 --> 00:00:05,310
‫Hello and welcome.

2
00:00:05,310 --> 00:00:10,830
‫In this lecture, we are going to introduce you to a new part of the animation blueprint called a state

3
00:00:10,830 --> 00:00:11,370
‫machine.

4
00:00:11,370 --> 00:00:12,780
‫Very useful part of it.

5
00:00:12,780 --> 00:00:18,990
‫And what it will allow us to do is if we hit a Boolean switch here, it's going to allow us to transition

6
00:00:18,990 --> 00:00:22,740
‫into a jumping state and then back down to grounded.

7
00:00:22,740 --> 00:00:27,090
‫Let's see how all of this works and how we can create this for ourselves.

8
00:00:28,050 --> 00:00:28,290
‫Okay.

9
00:00:28,290 --> 00:00:33,480
‫So we've got this really weird behavior when we jump, which just means that we end up running in midair,

10
00:00:33,480 --> 00:00:36,270
‫which is obviously not a very good look.

11
00:00:36,480 --> 00:00:41,790
‫Now, to fix this, we're going to need to learn about a whole new animation concept called an animation

12
00:00:41,790 --> 00:00:42,570
‫state machine.

13
00:00:42,570 --> 00:00:44,640
‫So this belongs in the animation blueprint.

14
00:00:44,640 --> 00:00:48,300
‫So go ahead and get that fired up if you haven't got it fired up already.

15
00:00:48,540 --> 00:00:55,080
‫And over in the anim graph, so far everything we've done in the graph has been through these nodes

16
00:00:55,080 --> 00:00:55,740
‫here.

17
00:00:55,860 --> 00:01:01,020
‫Now, what I want to show you is how we can add something new, something called a state machine.

18
00:01:01,110 --> 00:01:07,110
‫We're going to right click and this is in the anim graph and we're going to look for state machine.

19
00:01:07,110 --> 00:01:11,620
‫And you can see that this ad, new state machine is one option here.

20
00:01:11,640 --> 00:01:15,380
‫Now, I want to show you that there's another way of doing this as well.

21
00:01:15,390 --> 00:01:17,910
‫If you right click all the way back.

22
00:01:17,910 --> 00:01:24,720
‫So if we right click in the anim graph and search for new state machine, then we've got this option.

23
00:01:24,720 --> 00:01:31,470
‫Here we click, it creates a new node and you can see that node has a single animation PO's output pin

24
00:01:31,740 --> 00:01:37,950
‫and over in the left hand pane in the My Blueprint, it's created this new state machine underneath

25
00:01:37,950 --> 00:01:39,360
‫our anim graph.

26
00:01:39,360 --> 00:01:45,480
‫So if you either double click on the new state machine or click it over in the anim graph, you see

27
00:01:45,480 --> 00:01:47,670
‫it takes you to this new window.

28
00:01:47,670 --> 00:01:48,900
‫So it's yet another thing.

29
00:01:48,900 --> 00:01:53,850
‫We've got our anim graph, our event graph, and now we've got this state machine graph.

30
00:01:54,510 --> 00:01:55,980
‫We can actually rename that.

31
00:01:55,980 --> 00:02:01,770
‫So we can give our state machine a better name by clicking it in the My Blueprint and hitting two.

32
00:02:01,770 --> 00:02:05,730
‫And we can call it locomotion because this is going to be all about locomotion.

33
00:02:05,730 --> 00:02:07,710
‫And then what does a state machine do?

34
00:02:07,710 --> 00:02:11,880
‫Well, a state machine is at its simplest, it's a set of if you right click.

35
00:02:11,880 --> 00:02:14,190
‫In fact, you can see there's a couple of options here.

36
00:02:14,190 --> 00:02:15,690
‫There's a comment, there's a conduit.

37
00:02:15,690 --> 00:02:19,950
‫But the most important thing is it states it is a machine full of states.

38
00:02:19,950 --> 00:02:22,860
‫And I can add a couple of states in here to give you an idea.

39
00:02:22,860 --> 00:02:25,050
‫So we've got state, state one, state two.

40
00:02:25,350 --> 00:02:29,670
‫And then if you drag off of this border, it creates something called a transition.

41
00:02:29,670 --> 00:02:32,550
‫So you can create a transition between states.

42
00:02:32,820 --> 00:02:38,730
‫And we've got this entry pin which basically is telling us where which state should be started.

43
00:02:39,120 --> 00:02:39,440
‫Okay.

44
00:02:39,450 --> 00:02:40,830
‫So let's take a little step back.

45
00:02:40,830 --> 00:02:42,300
‫What does this all mean?

46
00:02:42,960 --> 00:02:49,140
‫Well, in each given state, if you double click on it, you can see that there is an output pin and

47
00:02:49,140 --> 00:02:55,350
‫that output pin can be used in the same way as our anim graph can be used to build up an animation pose.

48
00:02:55,350 --> 00:03:00,150
‫So in its simplest form, we might just decide to stick an animation in here.

49
00:03:00,150 --> 00:03:03,540
‫So select any old animation playability, for example.

50
00:03:03,540 --> 00:03:09,540
‫And that's the animation that's going to be played when the state machine is in a given state.

51
00:03:09,930 --> 00:03:11,820
‫Now, how do we get into a given state?

52
00:03:11,820 --> 00:03:15,060
‫Well, we might get into a given state because our entry node points to it.

53
00:03:15,060 --> 00:03:16,710
‫And so that's the default state.

54
00:03:16,710 --> 00:03:18,060
‫That's where we start off.

55
00:03:18,270 --> 00:03:21,990
‫But then we might get to a state via a series of transitions as well.

56
00:03:22,350 --> 00:03:27,150
‫So the transitions each have properties, you can double click on a transition and you can see that

57
00:03:27,150 --> 00:03:27,390
‫again.

58
00:03:27,390 --> 00:03:32,340
‫We get this node editor pop up and we can have some sort of boolean property.

59
00:03:32,340 --> 00:03:39,030
‫So I don't know we could have some thing like is dead, we can get is dead we can pipe that into here

60
00:03:39,030 --> 00:03:41,820
‫and now every time is dead is true.

61
00:03:41,850 --> 00:03:48,120
‫We're going to make the transition if we're in this original state, if we are dead, then we'll make

62
00:03:48,120 --> 00:03:52,200
‫the transition into state one and we'll start playing the animation in State one.

63
00:03:52,200 --> 00:03:57,870
‫And then if the transitions from State one are true, for whatever reason, we might make the transition

64
00:03:57,870 --> 00:03:59,070
‫over to State two.

65
00:03:59,610 --> 00:04:05,880
‫Okay, so this is all very well and good in theory, but how does this help us in practice with running?

66
00:04:06,300 --> 00:04:11,130
‫Well, for example, we might want a state that says grounded.

67
00:04:11,760 --> 00:04:16,440
‫And in the grounded state, we're going to play our ground locomotion.

68
00:04:16,440 --> 00:04:21,520
‫So if we go back up to our anim graph, what is our grounded locomotion?

69
00:04:21,540 --> 00:04:23,940
‫It is basically everything here.

70
00:04:23,940 --> 00:04:30,720
‫Before the we add our idle combat offset, there's this locomotion blend space is our grounded offset.

71
00:04:30,720 --> 00:04:39,300
‫So I'm going to cut the nodes here, go and hook up my locomotion state machine to pass in to our aim

72
00:04:39,300 --> 00:04:40,110
‫offset.

73
00:04:40,230 --> 00:04:45,480
‫Then I'm going to go into the locomotion state machine, go into the grounded state and paste in those

74
00:04:45,480 --> 00:04:48,600
‫nodes here and connect them up to the output pin.

75
00:04:48,750 --> 00:04:52,620
‫So let's follow what's going on here at the anim graph level.

76
00:04:53,130 --> 00:04:58,320
‫First of all, we are running the animation locomotion state machine.

77
00:04:58,500 --> 00:05:04,380
‫And because I haven't hooked this up, but because the entry pin points to the grounded state, we're

78
00:05:04,380 --> 00:05:08,520
‫automatically in the grounded state, it's going to go into there, figure out, okay, we've got a

79
00:05:08,520 --> 00:05:12,390
‫blend space, we blend it using our variables, then we output this.

80
00:05:12,390 --> 00:05:16,140
‫That becomes the output of our state machine as a whole.

81
00:05:16,140 --> 00:05:21,120
‫And then it feeds through into the combat animation, which feeds through into our death animation,

82
00:05:21,120 --> 00:05:23,490
‫which feeds into our final output.

83
00:05:23,820 --> 00:05:30,660
‫So hopefully now what we'll see when we compile it is actually nothing really has changed because there's

84
00:05:30,660 --> 00:05:32,580
‫only one state in our state machine.

85
00:05:33,270 --> 00:05:36,780
‫However, if we're jumping then we can introduce a new state.

86
00:05:36,780 --> 00:05:43,740
‫For that we go ad state, then we can have airborne as a state, and in this state we won't be playing

87
00:05:43,740 --> 00:05:44,760
‫the same animations.

88
00:05:44,760 --> 00:05:48,990
‫We're essentially switching out those animations in the anim graph up.

89
00:05:48,990 --> 00:05:54,210
‫At this level, we're saying that this node is going to switch to playing different animations when

90
00:05:54,210 --> 00:05:56,070
‫in the Airborne State.

91
00:05:56,070 --> 00:06:00,450
‫So we want to go into the Airborne State and make sure we have an animation selected here.

92
00:06:00,450 --> 00:06:05,640
‫So I'm going to pull off of that result pin and I'm just going to look for a jump.

93
00:06:05,640 --> 00:06:12,630
‫And particularly I'm going to look for the jump apex combat combat because that has as aiming Apex because

94
00:06:12,630 --> 00:06:19,020
‫this will be the top of our jump and then we're going to go out of the anim graph, then we're going

95
00:06:19,020 --> 00:06:23,430
‫to go out to the locomotion level and we'll notice that there's a problem here.

96
00:06:23,520 --> 00:06:28,110
‫There's no way for us to get to the Airborne State because there isn't a transition that leads us there.

97
00:06:28,410 --> 00:06:34,950
‫So what we want to do is drag from the border of grounded on to the airborne state and we want to double

98
00:06:34,950 --> 00:06:38,340
‫click in there because we want to create a transition here.

99
00:06:38,340 --> 00:06:42,090
‫And I'm just going to do a transition based on a variable which we don't currently have.

100
00:06:42,090 --> 00:06:50,610
‫So if I go over to my blueprints, add a variable and have an is airborne as a boolean variable in here,

101
00:06:50,610 --> 00:06:58,050
‫then I can pull that over in to this node editor for our grounded transition.

102
00:06:58,710 --> 00:07:05,910
‫And then we can hook that up so that what we're saying is this transition is possible when we are airborne

103
00:07:06,270 --> 00:07:11,490
‫and then we want a converse transition that goes from airborne to grounded.

104
00:07:11,640 --> 00:07:19,410
‫And if we click on double click on that one, then we can put in a knot node which basically negates

105
00:07:19,410 --> 00:07:25,850
‫the boolean and then we can put in the is airborne boolean as well.

106
00:07:25,860 --> 00:07:32,280
‫So that at the end what we've got here, if we go to our anim preview editor tab over to the right,

107
00:07:32,280 --> 00:07:38,310
‫we can flip this switch and we go into that airborne state playing the airborne animation.

108
00:07:38,310 --> 00:07:44,430
‫And if we flip it again, we go back in to our grounded locomotion and you can see that all of this

109
00:07:44,430 --> 00:07:46,500
‫is going to be working with our aim pitch as well.

110
00:07:46,500 --> 00:07:50,820
‫If I move the aim pitch pointing up, then I hit an airborne.

111
00:07:50,820 --> 00:07:54,530
‫You can see we keep aiming in the direction that we should be aiming.

112
00:07:54,540 --> 00:08:00,750
‫Okay, so I've got a mini challenge for you, apart from getting the state machine set up like this,

113
00:08:00,750 --> 00:08:06,690
‫if you haven't been following along already, what I would like you to try and do is see if you can

114
00:08:06,690 --> 00:08:07,470
‫find a way.

115
00:08:07,470 --> 00:08:14,130
‫At the moment when we click is airborne, we get this weird glitching looping of this animation, this

116
00:08:14,130 --> 00:08:15,360
‫airborne animation.

117
00:08:15,360 --> 00:08:18,810
‫See if you can make it so that this animation doesn't loop.

118
00:08:18,810 --> 00:08:23,640
‫So if you can find your way around the anim blueprint, which can be quite hard to navigate and see

119
00:08:23,640 --> 00:08:24,870
‫if you can find that property.

120
00:08:25,170 --> 00:08:25,680
‫Welcome back.

121
00:08:25,680 --> 00:08:28,260
‫So hopefully you've gone and given this a shot.

122
00:08:28,260 --> 00:08:30,510
‫So where would we start to think about this?

123
00:08:30,510 --> 00:08:33,120
‫How would we start to navigate around this blueprint?

124
00:08:33,690 --> 00:08:39,600
‫Well, for a start, we know that this problem is coming from our locomotion state machine.

125
00:08:39,840 --> 00:08:45,210
‫So let's go in there and we can see that the thing that is playing the state that's currently playing

126
00:08:45,210 --> 00:08:46,680
‫is the airborne state.

127
00:08:46,680 --> 00:08:52,860
‫So let's go into that and you can see that the jump apex combat is just looping round and round and

128
00:08:52,860 --> 00:08:55,260
‫it's clearly creating this problem here.

129
00:08:55,470 --> 00:09:02,490
‫So if we click on that animation and look at the details, you can see that we have got this loop animation

130
00:09:02,490 --> 00:09:03,540
‫property set.

131
00:09:03,990 --> 00:09:11,460
‫If I uncheck that and then recompile our animation blueprint, then I go and hit the is airborne.

132
00:09:11,730 --> 00:09:21,330
‫You can see it plays that jump apex just once and then it proceeds to hold that animation until we uncheck

133
00:09:21,330 --> 00:09:25,830
‫the box, at which point it transitions back to our locomotion state machine.

134
00:09:25,830 --> 00:09:29,070
‫Let's see all of that working if we had a bit of speed, if we were moving.

135
00:09:29,070 --> 00:09:36,030
‫So here we are running, we add our is airborne, it goes into our jump apex until we are no longer

136
00:09:36,030 --> 00:09:40,350
‫airborne, at which point we transition back to being running on the ground.

137
00:09:40,350 --> 00:09:41,400
‫So that's it for this lecture.

138
00:09:41,400 --> 00:09:46,710
‫We've been introduced to a whole new concept, a lot to take in the idea of an animation state machine

139
00:09:46,710 --> 00:09:52,890
‫we've seen about states and how we get into them via transitions, and we've seen how that can be driven

140
00:09:52,890 --> 00:09:57,690
‫by a boolean value to allow us to have a jump state.

141
00:09:57,690 --> 00:10:02,250
‫In the next lecture, we're going to hook this up to gameplay and refine things further.

