1
00:00:00,000 --> 00:00:09,360 
right we're back once again end up to
this point we've actually accomplished

2
00:00:09,360 --> 00:00:13,950 
quite a bit if we just do a really quick
play test we've got a character that we

3
00:00:13,950 --> 00:00:19,050 
can move and rotate he can shoot his
weapon we have an enemy that will chase

4
00:00:19,050 --> 00:00:22,590 
him down but right now our projectiles
don't really do anything

5
00:00:23,279 --> 00:00:29,400 
what we want is for them to damage the
enemy and then eventually destroy him

6
00:00:29,400 --> 00:00:31,890 
so that's what we're going to do in this
video we're going to set up that

7
00:00:31,890 --> 00:00:37,440 
damaging behavior between the
projectiles and the enemy to start this

8
00:00:37,440 --> 00:00:42,360 
off we're going to begin inside the
enemy character class we need to

9
00:00:42,360 --> 00:00:49,829 
basically expose the ability to transfer
damage to talk to that health value that

10
00:00:49,829 --> 00:00:54,360 
we set up in c++ because actually did
two things in c++ if you recall we set

11
00:00:54,360 --> 00:01:02,070 
up these variables and then we also
created the calculate health function

12
00:01:02,070 --> 00:01:05,460 
which is really just going to take an
incoming Delta add it to the existing

13
00:01:05,460 --> 00:01:09,750 
health and then store whatever that new
value is as the new health which is

14
00:01:09,750 --> 00:01:15,390 
great but we need though is a way to
talk between blueprints the projectile

15
00:01:15,390 --> 00:01:20,790 
is one blueprint the enemy is another
and we need a way to communicate in

16
00:01:20,790 --> 00:01:25,259 
between them and the way we do that
communication or one of the ways in

17
00:01:25,259 --> 00:01:29,400 
which we can do that communication is
with an interface so we're going to make

18
00:01:29,400 --> 00:01:35,040 
a blueprint interface and use that to
communicate with that calculate health

19
00:01:35,040 --> 00:01:39,360 
function that we set up in c++ so to to
set this up

20
00:01:40,020 --> 00:01:43,920 
actually before we send anything out let
me kind of describe i guess in general

21
00:01:43,920 --> 00:01:50,520 
terms what an interface is an interface
is a collection of unimplemented

22
00:01:50,520 --> 00:01:55,079 
functionality that sounds like a real
that's really a programmer a way to

23
00:01:55,079 --> 00:01:57,869 
explain it so let me think of a
different way to say i have two people

24
00:01:57,869 --> 00:02:02,009 
in front of me was a bob and tom

25
00:02:02,009 --> 00:02:06,689 
we have these two characters Bob and Tom
and if I tell Bob to tell me a story Bob

26
00:02:06,689 --> 00:02:10,020 
might tell me about how he walked home

27
00:02:10,020 --> 00:02:14,130 
last night and stop by the grocery store
and bought something for dinner but tell

28
00:02:14,130 --> 00:02:17,910 
Tom to tell me a story he might tell me
about something he did last weekend

29
00:02:17,910 --> 00:02:23,040 
maybe he went camping maybe he but well
the point is he did something totally

30
00:02:23,040 --> 00:02:27,210 
different than Bobby's they both had two
different results that they gave back to

31
00:02:27,210 --> 00:02:31,320 
me even though I gave them the same
command both just told him tell me a

32
00:02:31,320 --> 00:02:36,300 
story when interface is how you set up
those generic commands like tell me a

33
00:02:36,300 --> 00:02:40,380 
story and then within each receiving
thing with it within each thing that

34
00:02:40,380 --> 00:02:44,220 
knows what that command is you can make
it define what that really means if

35
00:02:44,220 --> 00:02:48,720 
that's confusing in anyway just watch
will make it all makes sense so let's

36
00:02:48,720 --> 00:02:52,620 
start by building our interface we're
going to right-click and go under the

37
00:02:52,620 --> 00:02:55,110 
blueprint submenu and there it is

38
00:02:55,110 --> 00:03:01,650 
blueprint interface so click and we're
going to call this I lowercase I I short

39
00:03:01,650 --> 00:03:07,830 
for interface damageable that is a
common code naming convention for

40
00:03:07,830 --> 00:03:13,380 
interfaces so I damageable we're going
to double-click it now we have no what

41
00:03:13,380 --> 00:03:17,670 
it has here is a function that will have
no implementation basically it's like

42
00:03:17,670 --> 00:03:22,590 
kind of declaring that we're going to do
something with this given name but we

43
00:03:22,590 --> 00:03:26,580 
don't really know what yet and we're
going to name this function is affect

44
00:03:26,580 --> 00:03:34,050 
health now affect health is going to
need to take in some value some numeric

45
00:03:34,050 --> 00:03:39,209 
value that we can use to affect our
health by some amount so under the input

46
00:03:39,209 --> 00:03:41,250 
section down here in the details panel

47
00:03:41,250 --> 00:03:45,180 
I'm sorry under it is in the details
panel excuse me I'll click on the new

48
00:03:45,180 --> 00:03:54,510 
button and let's set this to a name of
Delta go and then take its type and set

49
00:03:54,510 --> 00:03:56,490 
it to a float

50
00:03:56,490 --> 00:03:59,910 
that's it that's all we have to do we're
not going to notice we can't even

51
00:03:59,910 --> 00:04:03,810 
connect any nodes to this because it's
all grayed out the purpose of an

52
00:04:03,810 --> 00:04:09,450 
interface is that you just define the
structure for what a-what functionality

53
00:04:09,450 --> 00:04:13,500 
you want and you define what that
functionality is within any object that

54
00:04:13,500 --> 00:04:17,160 
implements that interface so the
function could mean different things to

55
00:04:17,160 --> 00:04:21,479 
different classes so let's compile and
save this and then we're actually done

56
00:04:21,479 --> 00:04:22,860 
with I damageable we don't

57
00:04:22,860 --> 00:04:27,449 
to do anything else to it we can close
it however we need to make sure that our

58
00:04:27,449 --> 00:04:33,960 
enemy character implements I damageable
now another fun fact just kind of

59
00:04:33,960 --> 00:04:39,960 
introducing you to some of the concepts
of working with interfaces any class in

60
00:04:39,960 --> 00:04:46,110 
your game can talk to this interface now
so like right now I could say affect

61
00:04:46,110 --> 00:04:50,490 
health and there it is an interface
message so he can send out a call

62
00:04:50,490 --> 00:04:54,419 
through the interface to talk to other
things he doesn't have to have anything

63
00:04:54,419 --> 00:04:59,639 
special to do that the interface just
has to exist but if he needs to receive

64
00:04:59,639 --> 00:05:05,279 
data source receive some sort of call
from the interface then he must

65
00:05:05,279 --> 00:05:09,840 
implement that interface and here's how
you do that if you go under your class

66
00:05:09,840 --> 00:05:14,460 
settings not class defaults class
settings there's a section here called

67
00:05:14,460 --> 00:05:17,699 
interfaces and there's implemented
interfaces right now none are

68
00:05:17,699 --> 00:05:21,930 
implemented so click the Add button and
from the jaw drop down you'll see I

69
00:05:21,930 --> 00:05:26,520 
damageable click on that and there you
go that's it that's all you have to do

70
00:05:26,520 --> 00:05:30,479 
make sure you compile and save once
you've done that now when you

71
00:05:30,479 --> 00:05:33,659 
right-click check it out if you type
affect health

72
00:05:34,560 --> 00:05:39,240 
there is now an event for it so this
event will be fired

73
00:05:39,240 --> 00:05:45,240 
whenever any other blueprint calls
affect health on this object so now you

74
00:05:45,240 --> 00:05:50,009 
basically just created a pathway where
other blueprints can talk to this guy

75
00:05:51,240 --> 00:05:55,259 
now what's going to happen when we call
this this is where r c++ code becomes

76
00:05:55,259 --> 00:06:01,409 
handy we can drag a wire out from this
and just say calculate health so we have

77
00:06:01,409 --> 00:06:03,839 
affected it from some outside source

78
00:06:03,839 --> 00:06:08,189 
now let's calculate and get our new
result and Delta just plugs right into

79
00:06:08,189 --> 00:06:10,199 
Delta that's it

80
00:06:10,199 --> 00:06:19,259 
now let's talk about what happens when
this guy dies so I remember calculate

81
00:06:19,259 --> 00:06:23,430 
health is going to take an incoming
Delta it's going to add that to the

82
00:06:23,430 --> 00:06:27,060 
existing health and then store that is
the new health so if if the value is

83
00:06:27,060 --> 00:06:32,159 
negative 20 the new result will be 80
because it's counting down and then it's

84
00:06:32,159 --> 00:06:36,470 
going to run that little helper function
we set up called calculate dead

85
00:06:36,470 --> 00:06:43,340 
and calculated just simply says hey did
help make it 20 or less yet because if

86
00:06:43,340 --> 00:06:46,400 
it did then set is dead too true

87
00:06:46,400 --> 00:06:49,760 
it hasn't yet leave is dead at false

88
00:06:49,760 --> 00:06:54,650 
that's great because what that means is
we can grab is dead and notice something

89
00:06:54,650 --> 00:06:58,280 
do you remember actually let me I'm just
gonna I'm gonna open up and show you

90
00:06:58,280 --> 00:07:02,060 
watch this this is pretty awesome if we
open up our base character class which

91
00:07:02,060 --> 00:07:05,270 
is going to open up visual studio will
let it do its thing

92
00:07:05,270 --> 00:07:09,950 
thank you prepare solutions haha we're
back that was nice and fast if you

93
00:07:09,950 --> 00:07:11,360 
remember

94
00:07:11,360 --> 00:07:16,190 
so there's calculate dead and you can
see it's just checking to see if

95
00:07:16,190 --> 00:07:20,600 
something's dead or not and it's setting
the value but if we take a look when we

96
00:07:20,600 --> 00:07:25,700 
declared the is dead boolean property we
had those keywords right blueprint

97
00:07:25,700 --> 00:07:31,490 
read-only it's not blueprint read/write
we can actually verify that check this

98
00:07:31,490 --> 00:07:35,870 
out if I close out of visual studio so
we don't need anymore let's go back over

99
00:07:35,870 --> 00:07:41,180 
to unreal and we go inside our enemy
character look at this my drag is dead

100
00:07:41,180 --> 00:07:41,990 
into the world

101
00:07:41,990 --> 00:07:47,840 
notice that set is grayed out i cannot
set that's because this is read-only but

102
00:07:47,840 --> 00:07:51,380 
i can get it which is all i need to do i
just wanted to point that out that side

103
00:07:51,380 --> 00:07:55,250 
of those keywords were actually doing
cool stuff so now we can take is dead

104
00:07:55,250 --> 00:08:03,350 
and let's test it to a branch and if is
dead

105
00:08:03,350 --> 00:08:09,890 
test out to be true then let's destroy
this actor so the enemy will just cease

106
00:08:09,890 --> 00:08:14,780 
to exist because that's how destruction
tends to work now let's just for

107
00:08:14,780 --> 00:08:20,450 
debugging purposes I'm going to set up
some temporary quote-unquote code here

108
00:08:20,450 --> 00:08:28,010 
as soon as we calculate health i want to
get our health and I want to print it

109
00:08:28,010 --> 00:08:35,870 
out to the screen let's do print string
will connect this into the line

110
00:08:36,550 --> 00:08:41,050 
now notice this takes in a string and
health is a float value if i try to

111
00:08:41,050 --> 00:08:42,039 
connect them

112
00:08:42,039 --> 00:08:45,519 
unreal is like oh you don't know the
difference between a float in a string

113
00:08:45,519 --> 00:08:48,910 
that's fine don't worry I'll convert
them for you

114
00:08:48,910 --> 00:08:54,160 
so cool what this means is we will get a
message from some outside source

115
00:08:54,160 --> 00:08:58,750 
spoiler alert it's going to be from the
laser blazer is going to call this we

116
00:08:58,750 --> 00:09:02,740 
will calculate our health will print out
whatever our new health happens to be

117
00:09:02,740 --> 00:09:07,089 
then we'll check and see if the
character is dead if it turns out they

118
00:09:07,089 --> 00:09:10,329 
did die then we're just going to destroy
them and they'll just disappear

119
00:09:10,329 --> 00:09:16,029 
let's compile and save now this won't do
anything just yet

120
00:09:16,930 --> 00:09:23,170 
we had to tell the project dial that it
can talk to the enemy by way of the

121
00:09:23,170 --> 00:09:28,420 
interface and here's how we're going to
set that up so if we take a look at our

122
00:09:28,420 --> 00:09:33,550 
projectile we have this nice collisions
fear we're going to use this to our

123
00:09:33,550 --> 00:09:35,079 
advantage

124
00:09:35,079 --> 00:09:39,220 
so let's uh start off by grabbing here
in our event graph we're going to begin

125
00:09:39,220 --> 00:09:46,570 
with event actor begin overlap and
overlap is what happens when two actor

126
00:09:46,570 --> 00:09:51,430 
two actors components are intersecting
the same space so basically that

127
00:09:51,430 --> 00:09:55,029 
collisions fear we set up if thats
overlapping something then we're gonna

128
00:09:55,029 --> 00:09:59,860 
get this this event call also it's a
good idea to double check your collision

129
00:09:59,860 --> 00:10:04,630 
settings so let's click on our
projectile collision this is currently

130
00:10:04,630 --> 00:10:10,329 
set to overlap all dynamic I'm kind of
okay with that but since we're only ever

131
00:10:10,329 --> 00:10:16,990 
shooting at pawns let's set this to
overlap only pawn it will probably work

132
00:10:16,990 --> 00:10:22,959 
better in the long run so compile and
save now back over here in the event

133
00:10:22,959 --> 00:10:26,890 
graph as soon as we detect an overlap
what's going to happen

134
00:10:26,890 --> 00:10:30,459 
well week we have at we have access to
the other actor

135
00:10:30,459 --> 00:10:34,870 
this is the other thing that we just
overlapped with so check this out we can

136
00:10:34,870 --> 00:10:41,170 
check to see if it implements a given
interface does it yes or no and the

137
00:10:41,170 --> 00:10:44,380 
interface we want to look for obviously
is I damageable

138
00:10:46,310 --> 00:10:51,200 
so I just held on the B key and click
that created a branch node super useful

139
00:10:51,200 --> 00:10:56,540 
shortcut once again i'll show you hold
down be click you get a branch and we'll

140
00:10:56,540 --> 00:11:02,960 
connect that up so we just tested to see
if whatever we just hit or whatever we

141
00:11:02,960 --> 00:11:07,760 
just overlapped with implements the I
damageable interface awesome

142
00:11:07,760 --> 00:11:14,900 
now if it does if it does we could just
damage that whatever it is we hit right

143
00:11:14,900 --> 00:11:21,380 
and that would work just fine but one
extra spoiler depending on how you set

144
00:11:21,380 --> 00:11:25,220 
up your arrow component where you're
shooting depending on where your gun is

145
00:11:25,220 --> 00:11:30,710 
placed it is possible in extreme
circumstances that you could end up

146
00:11:30,710 --> 00:11:36,080 
colliding with overlapping the player in
effect it's kind of like saying you have

147
00:11:36,080 --> 00:11:41,029 
the ability for the player to shoot
himself or put another way you could

148
00:11:41,029 --> 00:11:45,140 
shoot other hero characters if you
modify this game to be multiplayer so

149
00:11:45,140 --> 00:11:50,180 
what I'd like to do is establish a
system where we then check to see if we

150
00:11:50,180 --> 00:11:53,660 
just overlap with the player and if we
overlap with the player

151
00:11:53,660 --> 00:11:57,110 
we're not going to do anything so I
would because in the at the end of the

152
00:11:57,110 --> 00:12:00,890 
day the reason I'm checking for this is
the player will eventually also

153
00:12:00,890 --> 00:12:05,270 
implement I damageable he doesn't right
now but he would test true at this point

154
00:12:05,270 --> 00:12:07,700 
we need to verify we didn't actually hit
him

155
00:12:07,700 --> 00:12:12,200 
here's how we're gonna do it let's go to
the hero character class so here we are

156
00:12:12,200 --> 00:12:13,700 
in the hero

157
00:12:13,700 --> 00:12:19,730 
let's go over to the event graph and
we're going to select his class default

158
00:12:19,730 --> 00:12:24,620 
properties not settings is defaults and
over the details panel at the very

159
00:12:24,620 --> 00:12:27,320 
bottom there's this actor category

160
00:12:27,320 --> 00:12:32,780 
expand that and there's this little
hidden property called tags tags are

161
00:12:32,780 --> 00:12:37,640 
just like tags on a whole lot of
different internet activities right

162
00:12:37,640 --> 00:12:42,620 
there just the ability to put some sort
of name in place that could mean

163
00:12:42,620 --> 00:12:43,220 
anything

164
00:12:43,220 --> 00:12:49,370 
so I like it hits the little plus B
let's add a new tag and let's call this

165
00:12:49,370 --> 00:12:58,320 
friendly awesome so we have a tag name
friendly so now we can look for that tag

166
00:12:58,320 --> 00:13:02,940 
it's compile and save and then over here
in our projectile we can take the other

167
00:13:02,940 --> 00:13:06,930 
actor now i'm going to use rear out
notes just so it's easy for you to see

168
00:13:06,930 --> 00:13:13,020 
what we're doing we can say has tagged
and look at there's a note for that

169
00:13:13,020 --> 00:13:16,530 
actor has tagged now what tagger we
looking for

170
00:13:16,530 --> 00:13:21,780 
obviously we're looking for friendly now
that just reports out a boolean value

171
00:13:21,780 --> 00:13:23,610 
didn't find the tag

172
00:13:23,610 --> 00:13:28,200 
yes or no let's do another branch will
down be and click so if this tested true

173
00:13:28,800 --> 00:13:34,710 
let's then test and see if he's got the
tag now here's the deal

174
00:13:35,430 --> 00:13:39,630 
whenever I get the result that I want
out of a branch i would rather that

175
00:13:39,630 --> 00:13:40,650 
result be true

176
00:13:40,650 --> 00:13:45,810 
basically i would like all of my tests
to return true if they can so we're

177
00:13:45,810 --> 00:13:51,540 
going to take actor has tagged actually
going to attach that to a not node its

178
00:13:51,540 --> 00:13:55,350 
kind of inverting it if you read this
out in plain English you would say hey

179
00:13:55,350 --> 00:14:01,470 
does this object not have the friendly
tag which is a little different than how

180
00:14:01,470 --> 00:14:06,510 
you actually say that because it turns
out you can see that in common everyday

181
00:14:06,510 --> 00:14:09,090 
we speak which is kind of annoying

182
00:14:09,090 --> 00:14:13,920 
ok so we check and see if they do not
have the tag we make sure they don't

183
00:14:13,920 --> 00:14:21,360 
have the tag and if they don't have the
tag then finally we can affect their

184
00:14:21,360 --> 00:14:30,780 
health so let's do another route node
now to make sure that we're calling

185
00:14:30,780 --> 00:14:38,700 
affect health on the right object let's
do it this way let's just say affect

186
00:14:38,700 --> 00:14:46,380 
health so now that is asking for a delta
right how much you're affecting the

187
00:14:46,380 --> 00:14:46,920 
health

188
00:14:46,920 --> 00:14:52,170 
let's set this to negative 20 remember
our c++ code is adding the values

189
00:14:52,170 --> 00:14:55,050 
together so if we want to decrement
health we need to set this to a negative

190
00:14:55,050 --> 00:14:55,950 
number

191
00:14:55,950 --> 00:15:00,510 
ok so we've done that but let's so let's
make this into a variable so I'm gonna

192
00:15:00,510 --> 00:15:05,790 
take Delta i'm going to right click on
it and promote that to a variable will

193
00:15:05,790 --> 00:15:06,810 
call this

194
00:15:06,810 --> 00:15:09,870 
damage

195
00:15:09,870 --> 00:15:17,790 
cool that's being stored now pretty much
no matter what happens I want us to

196
00:15:17,790 --> 00:15:22,980 
destroy this laser or this projectile
when we're done so make a destroy actor

197
00:15:22,980 --> 00:15:28,800 
node and after we've affected health we
want to destroy the actor if we hit

198
00:15:28,800 --> 00:15:36,480 
something that did not implement the
interface also destroy the actor but if

199
00:15:36,480 --> 00:15:38,670 
we hit something and it turned out to be
the player

200
00:15:38,670 --> 00:15:41,760 
we're gonna do nothing so we'll leave
false disconnected and i'll use some

201
00:15:41,760 --> 00:15:44,400 
rear out notes to make this a little bit
cleaner

202
00:15:44,400 --> 00:15:50,820 
ok so if you need to see that whole
network again let's stretch this out

203
00:15:50,820 --> 00:15:55,500 
just a little bit i'll i'll try to
condense things down as best I can so we

204
00:15:55,500 --> 00:15:58,500 
can fit them all on the screen for just
a moment bear with me

205
00:15:59,370 --> 00:16:03,510 
bear with me there we go

206
00:16:04,110 --> 00:16:08,730 
and then pull listen so there you go so
begin overlap check and see if it

207
00:16:08,730 --> 00:16:13,050 
implements the interface if it does
check and make sure that it doesn't have

208
00:16:13,050 --> 00:16:16,620 
the friendly tag and if that's true
meaning it doesn't have the friendly tag

209
00:16:16,620 --> 00:16:22,350 
let's go ahead and affect its health
alright awesome so let's compile and

210
00:16:22,350 --> 00:16:26,850 
save let's come out here to our map let
me hit ctrl s to save everything let's

211
00:16:26,850 --> 00:16:33,240 
hit play and he is i'll check it out you
see his health dropping account all the

212
00:16:33,240 --> 00:16:34,680 
way down to 20 just like that

213
00:16:34,680 --> 00:16:40,770 
hit him again he's gone booms we got it
we're doing damage to the enemy now that

214
00:16:40,770 --> 00:16:46,260 
we've confirmed that however just to be
on the nice and neat side let's go into

215
00:16:46,260 --> 00:16:53,910 
our enemy and let's remove this little
portion of the graph that is reporting

216
00:16:53,910 --> 00:16:59,339 
that out we don't really need it we know
it's working so compile save play one

217
00:16:59,339 --> 00:17:05,339 
more time and now we shoot after five
shots player of the enemy goes away

218
00:17:05,339 --> 00:17:09,510 
which is perfect so we have the ability
to damage the enemy

219
00:17:09,510 --> 00:17:13,949 
that's great that is going to wrap
things up for this video thanks a lot


