Welcome back.
So we have some random locations that we generate every time we cast our spell.
And it's looking good.
And what I'd like to do next is load these points asynchronously.
Now I say load.
I don't really mean that we're loading all the points at once, but I'd like to create a timer of sorts
that will go through them one at a time.
And that way we can go and do things that we want, like spawn our shard particles, because I don't
want them all to just pop up all at the same time.
I want them to go one after the other according to a sort of set amount of time.
So I'm going to go into my aura abilities arcane arcane shards and open my gameplay ability here.
Now, all of these points, these debug spheres pop up all at the same time, because a for each loop
will just execute all at the same time.
I mean, it's not really at the same time, it's one after the other, but very, very rapidly.
And they'll pop up all on the same frame.
Now I'd like them to pop up separated by an amount of time, and we've seen how we can use timers for
this.
You know, there are different ways to go about doing this.
One is to do a delay and the loop the wire back around and execute the same thing again.
I like to use timers.
I tend to think those are cleaner.
And I'm going to just take these parts here where we're just cleaning up.
We're hiding the magic circle again.
Showing the mouse cursor is inherent in that we're destroying the point collection and we're ending
the ability after a point two second delay, I'm going to take all of these and just set them aside
for now.
We do want to do them, but I want to get rid of this for each loop.
I'm going to keep my draw debug sphere.
I'm going to put that up there.
But right after the ground points is cached off, I'd like to set a timer.
So I'm going to drag off and set timer and we'll set timer by event.
You can also do by function name.
There's several options here, but I like to set a timer by an event and create a custom event.
And the custom event here is going to do something every iteration of this timer.
It's going to basically spawn a shard.
I'm going to refer to one Niagara system as a shard.
So I'm going to call this spawn shard for lack of a better name.
I think that's descriptive enough, and for the time we can have a sort of shard tick rate of sorts,
a delta time for spawning shards.
So we can call this.
We'll promote it to a variable and we'll call it shard spawn Delta time.
And I'm going to set this to something like 0.2, maybe 0.1.
We'll start at 0.2 and we'll see how that feels.
And I'll go ahead and reroute this red node.
So that these things look nice and neat.
So we have a shard spawn Delta time.
I'm going to check looping here for my set timer by event.
And for each iteration of this timer, we're going to do a few things.
Right now, what I want to do is get an element from ground points each time, but I want to get a different
element.
I want to loop over them as if this were a for loop, but it's really not.
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
array.
Well, we're passing in num points here.
So what we can do is make that a member variable of this ability.
So I can promote this to a variable and call this num points.
And if I compile, I'll see that that's set to 11 because it was already 11 there.
And now that we have num points, we can have a count.
We can keep count, keep track of how many that we've spawned already.
So I'm going to make another variable.
And this can be called count.
And it's going to be an integer, and it's going to start off at zero.
And every time we spawn a shard, or in this case we're just drawing debug spheres.
But every time we do that, we can take our count and we can increment it by one.
And just like C plus plus has a plus plus, so does blueprint.
And it's going to do what plus plus and C plus plus does.
It's going to take count increment it by one.
And now count will be changed.
So it's like setting count equal to itself plus one okay.
So that's great.
But we're going to need to check that condition.
Just like a while loop or a for loop does.
So we need to take our count right here.
And we need to make sure that it's still less than.
NUM points.
So we're going to say count is less than num points.
It's just like creating a for loop and using this as that loop condition.
We're going to have a branch here.
So we're going to say if count is less than num points.
If that's true then we can go on with our lives and spawn debug spheres.
We can spawn one debug sphere increment count and then we'll resume.
Now where are we going to spawn it.
Well we need to get it from ground points.
So we're going to get ground points.
We're going to get a copy of one of its scene components.
And we're going to use count as the index.
Because count is kind of like the eye of a for loop.
I always use eye, but you could call this index if you wanted to as well.
But either way we're getting from ground points one of those scene components and we can use that components
world location.
We can get world location from it and hook that into the center for draw debug sphere.
And.
We're checking that loop condition.
And what we can do is we can exit in the false case.
If this condition no longer evaluates to true, then we have all this stuff that we were doing at the
end there.
We can go ahead and do that.
But the hide magic circle business, I don't want to wait until we're done spawning all of these or
showing all these spheres.
I'd actually like to hide the magic circle right away, right after we've set the timer.
So like, right up here, I'm just going to put it here.
So we can hide that magic circle right away, and then we can start seeing our spheres.
And then at the end, we'll have a point two second delay, destroy that point collection and end the
ability.
So with that, let's see how this looks in action.
So I can go ahead and press one and press one.
And there we have our points.
Now I'm noticing a slight delay before the first one.
And we can really see that if we take our shard spawn delta time and increase it to say 0.5 or even
a whole second.
Let's see what this looks like when we spawn our spheres.
I'm going to press it right now.
Actually, I need to press it again, so I'm going to press it again right now.
Okay.
See, a whole second went by before we had our spawn shard called, and that's even with an initial
start delay of zero.
So what we are going to do here is we're going to just call spawn shard right away, right after we
set the event, and that's going to increment the count.
It's going to do all this stuff.
So I'm going to take my event spawn shard.
And just call it right away.
That's one thing.
And another thing I want to do is I want to promote this timer to a variable so that we can clear and
invalidate it once we're done.
So I'm going to go ahead and take this return variable, promote it and call this shard spawn timer
and hook that up.
And then in the false case here, if we fail the loop condition we're going to take shard spawn timer
and call clear and invalidate timer by handle.
And we'll hook that up right there, like so.
And that takes care of cleaning up the timer.
Okay, let's try this now.
Let's go ahead and press play.
I should have a whole second delay between these spheres.
So I'm going to press the one key and I'm going to press it again right now.
And there's the sphere.
So as we can see we get it executed right away.
And then we get all the others and we can adjust shard spawn delta time.
We can set it really quick like 0.1.
And we'll just get these popping up all over the place like this.
That looks pretty cool.
And if we wanted a little slower, well, we can just adjust it.
I think point two is a pretty good time, but we aren't really going to know until we're actually spawning
those shards and we see what they look like.
And that's going to be one of our next tasks.
So before wrapping up, I think I'd like to just make sure that things are not too messy on the blueprint
front.
We don't want this to be confusing and out of hand, so I just want to make sure things are looking
good here.
So we can clean this up just a bit.
I actually don't think I need that reroute node there.
Okay.
That's looking good.
All right.
And with that, we can go ahead and wrap up.
Excellent job.
I'll see you in the next video.