WEBVTT

00:07.390 --> 00:08.590
Welcome back.

00:08.620 --> 00:14.530
Now that we have a magic circle class, it's time to show these on demand.

00:14.560 --> 00:21.640
I'd like to have easy to use functions to show and hide a magic circle and have it follow the mouse.

00:21.670 --> 00:25.360
Now, this is something I'd like to do on the player controller.

00:25.360 --> 00:33.400
The player controller will be valid locally, and we should be able to show these magic circles if we

00:33.400 --> 00:35.170
were to say spawn one.

00:35.170 --> 00:38.410
So I'd like to have some variables on our player controller.

00:38.410 --> 00:46.630
For that, I'm going to close the editor and go ahead and open my public folder, go to player and open

00:46.630 --> 00:47.950
or a player controller.

00:47.950 --> 00:50.320
And we're going to add a couple variables to this.

00:51.010 --> 00:55.000
Now here in the private section, I can add a couple things.

00:55.000 --> 01:02.530
For one, if I'm going to want to spawn one of these Magic Circle actors, I need a Uclass to spawn.

01:02.530 --> 01:09.430
So I'm going to make a subclass of to specify the class to spawn, and this is going to be an a magic

01:09.430 --> 01:11.170
circle actor.

01:11.850 --> 01:14.850
Now we can forward declare magic circle here.

01:14.850 --> 01:19.320
So I'm going to go ahead and do that class a magic circle.

01:21.170 --> 01:23.960
As that's the name of our Magic Circle class.

01:23.960 --> 01:26.510
And we have the you class.

01:27.200 --> 01:29.390
And it looks like I misspelled it there.

01:29.420 --> 01:31.280
There it is a magic circle.

01:31.280 --> 01:33.710
Let's make sure I didn't misspell it up here.

01:34.040 --> 01:35.000
Looks good.

01:35.640 --> 01:38.250
And I'm going to call this Magic Circle class.

01:41.420 --> 01:44.930
And this one will set the class in blueprint.

01:44.930 --> 01:47.420
So it's going to be edit defaults only.

01:47.420 --> 01:53.660
And in addition to Magic Circle class, we're going to want to be able to spawn one and keep a pointer

01:53.660 --> 01:55.520
to that magic circle.

01:55.520 --> 02:02.150
So I'm going to also create a t object pointer of type a magic circle.

02:04.430 --> 02:07.880
And this is going to be the magic circle itself.

02:09.380 --> 02:15.230
And this gets a new property as well, but we don't really need to expose it to blueprint.

02:15.230 --> 02:21.020
And for our magic circle, I'd like a function that we can use to spawn this thing.

02:21.020 --> 02:26.090
And that function I think, can be public.

02:26.390 --> 02:32.270
That way we can access the player controller and call this from outside the class, and I'm going to

02:32.270 --> 02:35.990
have a void show magic circle.

02:36.850 --> 02:38.830
And we'll go ahead and have a void.

02:38.830 --> 02:40.570
Hide magic circle.

02:43.490 --> 02:47.120
So we can go ahead and define these functions.

02:48.680 --> 02:57.950
And I'd like to lazily spawn our magic circle, because chances are you won't be always using the Arcane

02:57.950 --> 02:58.700
Shard spell.

02:58.700 --> 03:01.220
Unless, of course, it's your favorite spell or something.

03:01.220 --> 03:08.240
But if you're not using arcane shards that much, there's no point in a magic circle even existing.

03:08.240 --> 03:11.810
Especially if the magic circle is going to use things like tick.

03:11.810 --> 03:17.930
If it's going to be updated every frame, and it will because we need to move it according to our cursor

03:17.930 --> 03:18.830
location.

03:18.830 --> 03:25.340
So for that reason, if we have a magic circle, yes, we can update it every frame.

03:25.340 --> 03:32.600
But if we're not even showing the magic circle, I'd like to just destroy it and we'll just create one

03:32.600 --> 03:39.200
whenever we need one in Show Magic Circle, and we'll set our magic Circle pointer, which we have down

03:39.200 --> 03:40.040
here.

03:40.040 --> 03:45.530
So at any point in time, this magic circle could be null or it could be valid.

03:45.530 --> 03:51.800
So if we call show Magic Circle, I'm going to want to spawn a new magic circle, which means I'm going

03:51.800 --> 03:53.720
to use get world spawn actor.

03:53.720 --> 04:00.620
And I'm going to spawn an actor of my magic circle type a magic circle, and I'm going to specify the

04:00.620 --> 04:04.310
you class, which is going to be my Magic circle class.

04:04.310 --> 04:11.690
And if I spawn this, then my magic circle is going to be valid because I'm going to store this in my

04:11.690 --> 04:14.000
magic circle pointer.

04:14.390 --> 04:21.890
Now, I don't need to use the spawn actor overload that takes in a location or a transform or a rotation.

04:21.890 --> 04:30.020
I'm going to set all of that stuff if my magic circle is a valid pointer, if it's actually in existence,

04:30.020 --> 04:35.540
if we've spawned one and in Hyde Magic Circle, I'm going to destroy that magic circle.

04:35.540 --> 04:40.280
So I'm going to take Magic Circle and call destroy on it.

04:41.890 --> 04:43.090
Like this.

04:43.120 --> 04:46.900
Now I'm going to first check if Magic Circle is valid.

04:46.900 --> 04:49.000
So is valid.

04:49.120 --> 04:50.530
Magic circle.

04:52.610 --> 04:57.650
Because if it's pending kill, I don't want to try to destroy it because it's already being destroyed.

04:57.650 --> 05:02.810
So we're going to make sure that it's valid first and then call destroy on it.

05:02.810 --> 05:11.990
And when we're actually spawning an actor, we should only spawn one if the magic circle is not valid,

05:11.990 --> 05:13.790
if it's not in existence.

05:13.880 --> 05:17.570
So we can say if not is valid.

05:17.750 --> 05:19.160
Magic circle.

05:21.040 --> 05:23.830
In that case, we'll go ahead and spawn a new one.

05:26.010 --> 05:32.160
Now, if we have a magic circle and it's valid, we should be updating its location.

05:32.160 --> 05:40.170
And every frame in player tick, we're performing a cursor trace and we're caching our trace destination,

05:40.170 --> 05:44.490
our cached destination right here in our cursor hit.

05:44.580 --> 05:48.900
In fact, we're just saving the entire hit result and cursor hit.

05:49.200 --> 05:55.770
So what we can do if we want to set our magic circle's location is we can set it using that hit result

05:55.770 --> 05:56.970
every frame.

05:56.970 --> 05:59.400
So I'm going to make a function here.

05:59.400 --> 06:05.940
It can be private I'm going to call it void update magic circle location.

06:06.420 --> 06:08.790
And this can be called in tick.

06:08.790 --> 06:09.990
And every frame.

06:09.990 --> 06:14.970
As long as we have a magic circle we can go ahead and update its location.

06:14.970 --> 06:20.310
And for that reason I'm going to check if is valid magic circle.

06:20.580 --> 06:22.710
That way we don't have to worry about this.

06:22.710 --> 06:26.610
If the magic circle isn't valid, and most of the time this is going to fail.

06:26.610 --> 06:30.390
So what we'll do is we'll take our magic circle.

06:31.770 --> 06:33.420
And we're going to update its location.

06:33.420 --> 06:39.570
We're going to call set actor location and we need to take our cursor hit.

06:40.170 --> 06:42.480
Dot impact point.

06:43.120 --> 06:44.410
We can use that.

06:44.410 --> 06:46.660
So we're updating that location.

06:46.660 --> 06:52.390
We can call Update Magic circle location in our tick function player tick.

06:53.820 --> 06:56.910
And most of the time the circle won't be valid.

06:56.910 --> 06:58.710
Unless, of course, we're showing it.

06:58.860 --> 07:06.000
Now show magic Circle and hide magic circle could both be blueprint callable functions, just so we

07:06.000 --> 07:09.510
can easily show and hide the circle from blueprint.

07:09.510 --> 07:10.650
And so I'd like to do that.

07:10.650 --> 07:13.470
I'm going to make them both a blueprint callable function.

07:14.610 --> 07:18.120
And this allows testing to be a lot easier for this.

07:18.120 --> 07:24.810
So with all that, let's go ahead and compile and launch so that we can test out showing that circle

07:24.810 --> 07:27.270
by calling a blueprint callable function.

07:27.980 --> 07:28.460
Okay.

07:28.460 --> 07:31.280
So we can go ahead and open up that magic circle.

07:31.280 --> 07:33.110
There's really nothing to do here though.

07:33.110 --> 07:40.070
We want to go into blueprints player and open up Aura Player controller so that we can set some things

07:40.070 --> 07:40.610
here.

07:40.610 --> 07:49.670
For one, we need to set that class for our magic circle so we can find that magic circle variable.

07:51.980 --> 07:56.450
Here it is magic circle class and we can set it to Beep Magic Circle.

07:56.450 --> 08:03.890
And with that we can just call Show Magic Circle on begin play and we can hide it.

08:03.890 --> 08:07.250
We can test that out by just using a delay.

08:07.850 --> 08:11.690
And we can delay for about, say, 5 or 6 seconds.

08:11.690 --> 08:17.150
And then we can call hide magic circle in which our magic circle will be destroyed.

08:17.150 --> 08:19.280
So let's try this out.

08:20.490 --> 08:21.960
We'll go ahead and compile.

08:22.470 --> 08:25.200
We'll save all and we'll press play.

08:25.530 --> 08:26.940
And here's our magic circle.

08:26.940 --> 08:28.620
It's following our mouse location.

08:28.620 --> 08:31.080
And in five seconds there it goes.

08:31.080 --> 08:31.980
It goes away.

08:31.980 --> 08:35.730
And we can try bringing it back again after another delay.

08:35.790 --> 08:38.970
I'm just going to duplicate these nodes.

08:38.970 --> 08:42.090
I'm also going to duplicate that delay.

08:42.090 --> 08:44.340
And I'll make it a one second delay.

08:44.340 --> 08:47.580
And after we hide the magic circle we'll wait for a second.

08:47.580 --> 08:52.650
And then we'll show the magic circle for another five seconds so we can try turning this on and back

08:52.650 --> 08:53.250
off.

08:53.700 --> 08:55.770
So it's on for five seconds.

08:55.950 --> 08:58.500
And we can now see that it's gone.

08:58.500 --> 09:00.060
And the second later it's back.

09:00.060 --> 09:02.880
Five seconds after that, we should see it go away.

09:04.090 --> 09:05.200
And there we go.

09:05.440 --> 09:11.560
So we only have a magic circle in existence once we've called show magic circle.

09:11.560 --> 09:16.840
And when we hide the magic circle, we destroy that actor so it doesn't exist anymore.

09:16.840 --> 09:21.310
And it's not doing things, say, in its tick function, for example.

09:21.310 --> 09:27.610
And that's really nice, because now we can do things in the Magic circle's tick and not worry that

09:27.610 --> 09:32.260
they'll be ticking like that when we're not even showing that magic circle.

09:32.260 --> 09:35.320
So we could take tick in our magic circle.

09:35.320 --> 09:38.080
We could take our magic circle decal if we like.

09:38.470 --> 09:44.830
We can call add local rotation if we wanted to, and we can just rotate the magic circle.

09:44.830 --> 09:52.990
We can go ahead and split the struct pin and we can take delta seconds, multiply it by some value,

09:52.990 --> 09:58.960
say ten or maybe eight something small and we can change its pitch.

09:58.960 --> 10:05.560
Now remember, if we show that magic circle, if we were changing its your it would be rotating about

10:05.560 --> 10:07.240
its z axis.

10:07.240 --> 10:14.470
But if we're changing its pitch, we're actually going to be rotating it about its y axis.

10:14.470 --> 10:17.560
So actually I think it's the role that we need to change.

10:17.560 --> 10:21.730
So we're going to actually add rotation to the role.

10:22.060 --> 10:25.960
And Magic Circle decal actually is not exposed to the event graph.

10:25.960 --> 10:30.700
So if we're going to want to play around here in the event graph with it, we're going to have to expose

10:30.700 --> 10:33.670
it so we can go ahead and close the editor.

10:33.670 --> 10:40.600
We can go to Magic Circle and take that decal and give it blueprint read only.

10:41.280 --> 10:44.100
So we can go ahead and launch the editor again.

10:45.090 --> 10:48.600
And with that, we should no longer have that error.

10:48.600 --> 10:50.250
We can compile just fine.

10:50.250 --> 10:55.170
And if we press play and now we see our decal is rotating and it looks great.

10:55.740 --> 10:56.400
Awesome.

10:56.400 --> 10:59.610
So I'm going to go ahead and remove this decal.

10:59.640 --> 11:00.750
I can't really select it.

11:00.750 --> 11:03.390
So I'm going to have to search for Magic Circle.

11:03.390 --> 11:07.380
Select that in the outliner remove that.

11:07.380 --> 11:13.320
And now we just have that decal and it's being spawned by our player controller.

11:15.230 --> 11:19.190
And of course it goes out and back in based on those delays that we have here.

11:19.190 --> 11:24.380
We're just playing around in blueprints at this point, but we now have the ability to show and hide

11:24.380 --> 11:29.930
the magic circle, and that's going to be crucial for our Arcane Shards ability.

11:29.930 --> 11:34.010
So excellent job, and I'll see you in the next video.
