Blueprint Essentials: Custom Loops | 14 | v4.2 Tutorial Series | Unreal Engine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to talk about creating your own custom types of loop now this is not something you may need to do very often and I want to throw out a general disclaimer in this video I'm going to modify an asset that is inside the engine you do this at your own risk if you follow along with what I'm doing you shouldn't break anything but if you do for some reason that is entirely your risk to make sure you're making a backup of things just in case you get a little bit overzealous so what I'm gonna do for starters is show you something what if we wanted a loop that had a delay loops can't delay so if we had something like a while loop and as part of the loop body we wanted it to stop and wait a few seconds before it fired off the next part of the loop body we can't do that that's because a loop has to complete everything in between tics what we can do however is leverage the fact that all of these loops are macros in and of themselves if you double click on a loop you jump down inside the actual blueprint graph that makes that loop possible so a while loop is really just a branch and a sequence that are fired off inside of a macro now I'm going to talk specifically about macros a little bit later in a separate video for now we're going to keep things really simple we simply have an input and we have a condition the branch checks the condition and if the condition is true it fires off a sequence the sequence first triggers the loop buddy and then it wraps back around and checks the branch again so the branch will continue to check in the condition and so on and so forth eventually the condition will read false unless you've made an infinite while loop and then it fires off false and that hits your completed output so that is in a nutshell how the while loop works now since that is within the standard macros there's nothing stopping us from making one of our very own so I'm going to close this and let's get this out of the way for just a moment I'm going to go over to the content browser and we're going to go into view options and turn on the show engine content checkbox now with that let's go into the engine folder and we'll search for standard macros now I could have just used what was already there I just wanted to make sure I showed you how to access these on your own so now we are looking at the list of standard macros I'm going to add a new macro and I'm going to call this while loop with delay so pretty simple so far now I'm going to add some inputs to this so we'll create a new input which will be an execution input so it has its own execution pin and we got to give it a name so we could just call it space and that that makes it blank so it looks a little bit more like most of the other inputs that we have now we need some other inputs as well so let's click the new button again and this one we will call delay this is going to be how long we want the delay to exist between loop executions this needs to be a float value we'll add another input as well and this will be the input for our condition and we'll give this a type of boolean so really just a straight forward will be run the loop yes or no now for outputs we're going to add a new output which we will call loop buddy and this needs to be an execution pin and another one called completed which is also an execution pin all right now it's easy so let's branch off from our execution pin on the input and we'll do a branch the branch just needs to check our condition if the condition is true then we run the loop the loop is going to consist of a sequence and that sequence is first going to fire off the loop body and then normally it would just wrap back around a branch but we're going to do instead is create a delay and if you just try to create a delay with context sensitivity on you won't be able to so turn off context sensitivity and suddenly it's there oh there's a delay and we're going to take that delay input and plug that into the duration now we'll take when once the delay is completed we'll wrap that back around to the branch and then once we hit false on the branch will run to complete it so it's a lot of overlapping wires lots of stuff going on here I'll try to kind of separate it out a little bit make it a little easier to see but yeah kind of a tangle so with that we can go ahead and save let's jump back over to our loops we don't need a little while loop here anymore but now if we actually let me show you something else real quick before we run away if we take a look at the while loop entry here you'll notice it has a category of utilities pipe symbol flow control let's just copy that and then we'll go back to loop with delay and we'll paste it in and for description we'll say while loop that has a set delay between loop executions there we go now we'll save once again so if we right-click and we jump down to utilities and there's flow control we will now see a while loop with delay so we have our very own custom loop so let's fire that off we'll just hard code a delay value of 2 seconds and for the loop body we're gonna do something really simple let's just do a print and it can just say hello that's fine and I'm not going to actually ever tell it to stop because now that we have a delay in there it doesn't have to keep executing in between each tick so I can now get this out of the way we can hit play and when I hit the F key it says hello and it looks like Hello is never going to go away actually let me change my delay a little bit that's because right as it goes away we spawn the other ones so let's do every one second and we'll compile that and hit play so when I hit F we just start getting a little stack of hellos and they're slowly rolling so the one on the bottom disappears and scoots up and another one pops in beneath it but the nice thing is that we have a while loop that is running rampant ly it's just never stopping however we are still able to play the game because of that delay because in computer time a second is an eternity that's a whole lot of time so that's a quick look at creating your own loops to do special things there just under the standard macros if you like any of the flow control elements and you'd like to work on them or make your own version of them you can do that so like we could take just a regular for loop with break or there's the for loop with breaker there so there's the the script that makes that possible so nothing stopping you from making your own version of that if you wanted to so again that's just what I wanted to show you a way to make your own custom loops that'll wrap things up for this video thanks a lot
Info
Channel: Unreal Engine
Views: 54,099
Rating: undefined out of 5
Keywords: UE4, Blueprints, basics, essentials, loops, Unreal
Id: Mxw391exhVg
Channel Id: undefined
Length: 7min 22sec (442 seconds)
Published: Wed May 28 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.