WEBVTT

00:07.230 --> 00:08.430
Welcome back.

00:08.460 --> 00:15.120
So we have some random locations that we generate every time we cast our spell.

00:15.120 --> 00:17.190
And it's looking good.

00:17.190 --> 00:23.130
And what I'd like to do next is load these points asynchronously.

00:23.130 --> 00:24.060
Now I say load.

00:24.060 --> 00:31.140
I don't really mean that we're loading all the points at once, but I'd like to create a timer of sorts

00:31.140 --> 00:33.960
that will go through them one at a time.

00:33.960 --> 00:41.730
And that way we can go and do things that we want, like spawn our shard particles, because I don't

00:41.730 --> 00:44.310
want them all to just pop up all at the same time.

00:44.310 --> 00:50.310
I want them to go one after the other according to a sort of set amount of time.

00:50.310 --> 00:57.540
So I'm going to go into my aura abilities arcane arcane shards and open my gameplay ability here.

00:58.080 --> 01:05.130
Now, all of these points, these debug spheres pop up all at the same time, because a for each loop

01:05.130 --> 01:07.950
will just execute all at the same time.

01:07.950 --> 01:12.930
I mean, it's not really at the same time, it's one after the other, but very, very rapidly.

01:12.930 --> 01:16.320
And they'll pop up all on the same frame.

01:16.320 --> 01:22.440
Now I'd like them to pop up separated by an amount of time, and we've seen how we can use timers for

01:22.440 --> 01:22.800
this.

01:22.800 --> 01:26.010
You know, there are different ways to go about doing this.

01:26.010 --> 01:32.100
One is to do a delay and the loop the wire back around and execute the same thing again.

01:32.100 --> 01:33.420
I like to use timers.

01:33.420 --> 01:35.250
I tend to think those are cleaner.

01:35.250 --> 01:40.770
And I'm going to just take these parts here where we're just cleaning up.

01:40.770 --> 01:43.080
We're hiding the magic circle again.

01:43.080 --> 01:48.300
Showing the mouse cursor is inherent in that we're destroying the point collection and we're ending

01:48.300 --> 01:53.100
the ability after a point two second delay, I'm going to take all of these and just set them aside

01:53.100 --> 01:54.030
for now.

01:54.030 --> 01:58.530
We do want to do them, but I want to get rid of this for each loop.

01:58.530 --> 02:01.950
I'm going to keep my draw debug sphere.

02:01.950 --> 02:03.750
I'm going to put that up there.

02:03.750 --> 02:08.460
But right after the ground points is cached off, I'd like to set a timer.

02:08.460 --> 02:13.830
So I'm going to drag off and set timer and we'll set timer by event.

02:13.830 --> 02:16.560
You can also do by function name.

02:16.800 --> 02:23.250
There's several options here, but I like to set a timer by an event and create a custom event.

02:23.900 --> 02:29.300
And the custom event here is going to do something every iteration of this timer.

02:29.390 --> 02:33.710
It's going to basically spawn a shard.

02:33.740 --> 02:38.270
I'm going to refer to one Niagara system as a shard.

02:38.270 --> 02:43.850
So I'm going to call this spawn shard for lack of a better name.

02:43.850 --> 02:53.450
I think that's descriptive enough, and for the time we can have a sort of shard tick rate of sorts,

02:53.450 --> 02:57.200
a delta time for spawning shards.

02:57.200 --> 02:58.790
So we can call this.

02:59.120 --> 03:05.570
We'll promote it to a variable and we'll call it shard spawn Delta time.

03:07.190 --> 03:12.350
And I'm going to set this to something like 0.2, maybe 0.1.

03:12.350 --> 03:15.350
We'll start at 0.2 and we'll see how that feels.

03:15.350 --> 03:18.020
And I'll go ahead and reroute this red node.

03:18.770 --> 03:22.100
So that these things look nice and neat.

03:23.990 --> 03:26.840
So we have a shard spawn Delta time.

03:26.840 --> 03:30.770
I'm going to check looping here for my set timer by event.

03:30.770 --> 03:37.010
And for each iteration of this timer, we're going to do a few things.

03:37.010 --> 03:44.510
Right now, what I want to do is get an element from ground points each time, but I want to get a different

03:44.510 --> 03:44.900
element.

03:44.900 --> 03:49.550
I want to loop over them as if this were a for loop, but it's really not.

03:49.580 --> 03:56.000
Now, if I want to do that, I need some kind of a count and I need to know how many points are in this

03:56.000 --> 03:56.690
array.

03:56.690 --> 03:59.120
Well, we're passing in num points here.

03:59.120 --> 04:04.010
So what we can do is make that a member variable of this ability.

04:04.010 --> 04:08.060
So I can promote this to a variable and call this num points.

04:10.700 --> 04:15.290
And if I compile, I'll see that that's set to 11 because it was already 11 there.

04:15.770 --> 04:19.190
And now that we have num points, we can have a count.

04:19.190 --> 04:23.810
We can keep count, keep track of how many that we've spawned already.

04:23.810 --> 04:25.880
So I'm going to make another variable.

04:25.880 --> 04:27.860
And this can be called count.

04:29.640 --> 04:33.450
And it's going to be an integer, and it's going to start off at zero.

04:33.450 --> 04:38.850
And every time we spawn a shard, or in this case we're just drawing debug spheres.

04:38.850 --> 04:44.430
But every time we do that, we can take our count and we can increment it by one.

04:44.430 --> 04:48.480
And just like C plus plus has a plus plus, so does blueprint.

04:48.480 --> 04:52.950
And it's going to do what plus plus and C plus plus does.

04:52.950 --> 04:55.800
It's going to take count increment it by one.

04:55.800 --> 04:58.050
And now count will be changed.

04:58.050 --> 05:01.860
So it's like setting count equal to itself plus one okay.

05:01.860 --> 05:03.510
So that's great.

05:03.510 --> 05:06.060
But we're going to need to check that condition.

05:06.060 --> 05:09.000
Just like a while loop or a for loop does.

05:09.000 --> 05:12.120
So we need to take our count right here.

05:12.120 --> 05:14.970
And we need to make sure that it's still less than.

05:15.980 --> 05:16.940
NUM points.

05:16.940 --> 05:19.370
So we're going to say count is less than num points.

05:19.400 --> 05:23.900
It's just like creating a for loop and using this as that loop condition.

05:23.900 --> 05:25.490
We're going to have a branch here.

05:25.490 --> 05:28.520
So we're going to say if count is less than num points.

05:28.520 --> 05:33.560
If that's true then we can go on with our lives and spawn debug spheres.

05:33.560 --> 05:38.540
We can spawn one debug sphere increment count and then we'll resume.

05:38.540 --> 05:40.310
Now where are we going to spawn it.

05:40.310 --> 05:42.470
Well we need to get it from ground points.

05:42.470 --> 05:43.880
So we're going to get ground points.

05:43.880 --> 05:47.660
We're going to get a copy of one of its scene components.

05:47.660 --> 05:49.820
And we're going to use count as the index.

05:49.820 --> 05:53.000
Because count is kind of like the eye of a for loop.

05:53.000 --> 05:57.140
I always use eye, but you could call this index if you wanted to as well.

05:57.140 --> 06:03.980
But either way we're getting from ground points one of those scene components and we can use that components

06:03.980 --> 06:04.850
world location.

06:04.850 --> 06:10.220
We can get world location from it and hook that into the center for draw debug sphere.

06:10.890 --> 06:11.820
And.

06:12.740 --> 06:15.080
We're checking that loop condition.

06:15.080 --> 06:20.420
And what we can do is we can exit in the false case.

06:20.420 --> 06:26.900
If this condition no longer evaluates to true, then we have all this stuff that we were doing at the

06:26.900 --> 06:27.740
end there.

06:27.740 --> 06:29.540
We can go ahead and do that.

06:29.540 --> 06:35.390
But the hide magic circle business, I don't want to wait until we're done spawning all of these or

06:35.390 --> 06:36.680
showing all these spheres.

06:36.680 --> 06:43.040
I'd actually like to hide the magic circle right away, right after we've set the timer.

06:43.040 --> 06:46.070
So like, right up here, I'm just going to put it here.

06:47.410 --> 06:53.020
So we can hide that magic circle right away, and then we can start seeing our spheres.

06:53.020 --> 06:58.930
And then at the end, we'll have a point two second delay, destroy that point collection and end the

06:58.930 --> 06:59.500
ability.

06:59.500 --> 07:04.600
So with that, let's see how this looks in action.

07:06.690 --> 07:10.110
So I can go ahead and press one and press one.

07:11.380 --> 07:13.090
And there we have our points.

07:17.530 --> 07:20.590
Now I'm noticing a slight delay before the first one.

07:21.640 --> 07:28.360
And we can really see that if we take our shard spawn delta time and increase it to say 0.5 or even

07:28.360 --> 07:29.500
a whole second.

07:30.090 --> 07:34.200
Let's see what this looks like when we spawn our spheres.

07:34.470 --> 07:37.230
I'm going to press it right now.

07:38.090 --> 07:42.710
Actually, I need to press it again, so I'm going to press it again right now.

07:43.260 --> 07:43.800
Okay.

07:43.800 --> 07:51.660
See, a whole second went by before we had our spawn shard called, and that's even with an initial

07:51.660 --> 07:53.220
start delay of zero.

07:53.400 --> 07:59.940
So what we are going to do here is we're going to just call spawn shard right away, right after we

07:59.940 --> 08:02.880
set the event, and that's going to increment the count.

08:02.880 --> 08:04.470
It's going to do all this stuff.

08:04.470 --> 08:08.070
So I'm going to take my event spawn shard.

08:09.860 --> 08:11.390
And just call it right away.

08:11.920 --> 08:13.000
That's one thing.

08:13.000 --> 08:19.210
And another thing I want to do is I want to promote this timer to a variable so that we can clear and

08:19.210 --> 08:20.950
invalidate it once we're done.

08:20.950 --> 08:27.400
So I'm going to go ahead and take this return variable, promote it and call this shard spawn timer

08:27.700 --> 08:30.580
and hook that up.

08:30.580 --> 08:36.640
And then in the false case here, if we fail the loop condition we're going to take shard spawn timer

08:36.640 --> 08:40.390
and call clear and invalidate timer by handle.

08:42.280 --> 08:46.120
And we'll hook that up right there, like so.

08:46.540 --> 08:49.720
And that takes care of cleaning up the timer.

08:51.310 --> 08:53.200
Okay, let's try this now.

08:53.200 --> 08:54.460
Let's go ahead and press play.

08:54.460 --> 08:57.310
I should have a whole second delay between these spheres.

08:57.310 --> 09:01.450
So I'm going to press the one key and I'm going to press it again right now.

09:01.450 --> 09:02.980
And there's the sphere.

09:02.980 --> 09:06.760
So as we can see we get it executed right away.

09:06.760 --> 09:11.590
And then we get all the others and we can adjust shard spawn delta time.

09:11.590 --> 09:14.860
We can set it really quick like 0.1.

09:14.860 --> 09:18.910
And we'll just get these popping up all over the place like this.

09:19.920 --> 09:21.300
That looks pretty cool.

09:24.000 --> 09:26.670
And if we wanted a little slower, well, we can just adjust it.

09:26.670 --> 09:33.630
I think point two is a pretty good time, but we aren't really going to know until we're actually spawning

09:33.630 --> 09:36.030
those shards and we see what they look like.

09:36.030 --> 09:39.030
And that's going to be one of our next tasks.

09:39.300 --> 09:46.230
So before wrapping up, I think I'd like to just make sure that things are not too messy on the blueprint

09:46.230 --> 09:46.620
front.

09:46.620 --> 09:53.730
We don't want this to be confusing and out of hand, so I just want to make sure things are looking

09:53.730 --> 09:54.600
good here.

09:57.150 --> 09:59.580
So we can clean this up just a bit.

09:59.580 --> 10:02.430
I actually don't think I need that reroute node there.

10:07.810 --> 10:08.440
Okay.

10:08.440 --> 10:09.880
That's looking good.

10:13.500 --> 10:14.100
All right.

10:14.100 --> 10:17.250
And with that, we can go ahead and wrap up.

10:17.250 --> 10:18.150
Excellent job.

10:18.150 --> 10:20.790
I'll see you in the next video.
