Using Blueprints to Enhance Your Unreal Engine Scenes | Webinar

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone and welcome to this unreal engine webinar on enhancing your unreal scenes using blueprints we've got a lot to cover today so i'm going to go ahead and jump right in to talking about some of the key takeaways that you should get from this webinar first of all we're going to do a quick introduction to what blueprints are as well as things like performance and what types of blueprints you work with and we'll look at the ui of blueprints and some of the workflow but rather than go through the ui and workflow by simply looking at the interface we're going to get some experience building blueprints and as we do we'll talk about those things then we're going to look at two examples today the first of which will be a walking animated person that moves along a custom path and we'll learn quite a few basics as we go through that particular example and after that we're going to get really detailed and move a lot faster and we're going to go through a multi-floor elevator system that you could use any amount of floors that you want and the elevator will go to the floors as it gets called to those floors so blueprints are a visual node-based scripting tool whereas normally you would write code using c plus but blueprint is designed to be much more artist and designer friendly and it provides very easy access to most of unreal's api that that is all of the different things that unreal's engine can do now blueprints are the same tool found throughout unreal's editing systems you've got level blueprints actor blueprints umg the the motion graphics system uses blueprint sequencer control rigs animation blueprints and on and on and on here are some of the blueprint types we'll be working with today first of all obviously we have our level blueprints these are for things that only exist in that one level and you want to avoid putting things in the level blueprint as much as possible you want to work in a more modular way and that brings us to actor blueprints actors or anything that can be placed inside of a level and this is going to be better for more reusable content things that can be put into multiple levels you also have your umg blueprints these are going to be for interacting with user interface and then also we'll be using an animation blueprint for controlling our character driven animation allowing us to blend between different states now there are some performance considerations when working with blueprint keep in mind it is slower than writing c plus plus code but again so much easier blueprint is compiled into what's known as bytecode which is then interpreted by a virtual machine built specifically for doing that and that's why it has some overhead and it's going to be slower than c plus which just runs natively on your machine typically when you're trying to do something in blueprint it's going to require more nodes than what you could do in c plus so it can be more verbose as they say it can be a little more difficult to create the same kind of thing you would easily more easily create in c plus plus if you know code also blueprint is not as scalable as c plus plus it's a lot harder to build larger systems that you could do in c plus plus next there are some things we want to avoid when we're working with blueprint some of you may have heard about the dreaded on-tick node it's best to avoid that because this is something that happens every frame of your simulation and that can be very expensive if you have a lot of things operating on tick but you don't always want to avoid it because there will be times when you need to fire something every tick just try to be conscious of that try to avoid it find other ways to do it we'll be looking at some ways that i use today where we only engage things when the user is in a collision volume or things like that also you want to avoid overly complex math doing things like that can put a lot of strain on the interpretation in the vm all these calculations having to be made it can really slow things down and also avoid large amounts of data big arrays with lots and lots of objects inside of them and then finally avoid excessive looping and branching in code looping is when you simply go back and run the same code over and over and branching is where you're determining if something is true or false and you go one way or the other based on that true or false test and so we'll try to avoid using that excessively we want to keep our branches and loops simple if possible one other thing we should consider is debugging and optimization techniques and we're just going to kind of briefly discuss them here but a few of these we'll actually look at as we work so the first thing is have a plan don't start building your blueprints until you've written everything down that you plan to do or use the flowchart system to figure out exactly what needs to happen also if you're going to have blueprints that talk to each other and need access to their variables and events be sure to create those variables and events first before you start getting into creating all the different graph networks inside of each blueprint that way when you start to work on the graphs you'll have those variables and events already available if you have a lot of repetitive node networks it's best to use functions and macros we won't really be looking at those today but you definitely want to check those out you can also simply collapse a group of nodes to make your blueprints look a little cleaner also be sure to use comments liberally so you can understand what your blueprints are doing and then a couple of great debugging techniques are to use print strings and to use simulation mode so that you can actually see the execution of your blueprint graph as you play an editor all right let's jump right in we don't have a lot of time today so rather than just go over all of the interface elements and and talk about them we're going to actually get our hands dirty and build our examples and as we build them i'll talk about different aspects of working with blueprints so the first thing is we need to create our first blueprint and to do that there are a couple of things we can do the easiest though is to right click on the content browser and choose blueprint class and then from here we have our list of blueprints we have all of our most used blueprint types here and these are going to be what our blueprint inherit from or inherits from and in this case we want to inherit from actor that allows us to place it in the level and we could choose pretty much every other class available to us inside of unreal if we need to but we just want actor and we'll call this bp my character all right and then we can place it in a level by simply dragging it in here let's go ahead and make use of it you can see it up here in our world outliner bp my character and all the basic details for it will be right here underneath let's go ahead and double click it to begin creating something here for our character here in the blueprint editor we open to the viewport by default the left side we have the components tab and the my blueprint tab components where we're going to be adding all of the assets that are going to be used by our blueprint and then our variables and functions and other things like that we can add here under my blueprint and on the right again we have a details panel for everything that we have selected from here we have our construction script tab which we can use to initialize variables and things like that when it's first created in the in the level and we have our event graph which is where we're going to be doing most of our work today so let's go ahead and start by adding the two elements that we need for our character and that's going to be a character component or skeletal mesh components we'll click the button here and then skeletal mesh and then second of all we need a spline component which we can use to animate so we'll search for spline and then that's what we want right there okay so now we have our spline and our character component but the character component is not selected yet so what we want to do is select that actually let's take our spline you can see it's parented under the skeletal mesh but we want it under the default route so let's just click and drag that to the default route let go and then attach so now they're both children of the default route and let's change our skeletal mesh name to sm character and under the details panel we're going to choose our skeletal mesh and we'll choose this nathan mesh here so if we go ahead and compile and save that we can see now that our guy is in the scene and it's got our spline path now for animation we're going to change the animation mode temporarily to use animation asset and then we're going to select the walking animation here all right but we're going to be changing that to a blueprint animation shortly but for now just for testing we're going to leave it like this also if we look on the my blueprint tab here down underneath variables so we can see we've already got access to the spline and the skeletal mesh but we're also going to need a variable here for controlling his walking speed so i'm going to click the add variable button this allows me to add a new variable and we'll just call this walking speed and by default it's going to be a boolean that's what the red color there is so everything is color coded inside of unreal but we're going to go ahead and click that to change it and we want to change that to a float or floating point value you can see the color for that is a greenish tint now we also want to make this variable public so that we can control the walking speed inside of the editor to do that we can click on the little eye icon here to open it up so now if we compile this and then we go into the editor with that blueprint node selected we should see walking speed here and it's currently set to zero let's go ahead and set it to something like two so back in blueprint keep in mind that variables are a way to allow you to store data that you need to reuse in your blueprint graphs and they've come in very handy you'll obviously see that we can make them public and edit them in the editor we can also use them to get references to other blueprints and other objects and work with them and we'll see some of that today now that we have all this set up let's jump over to our event graph and begin constructing our character in our event graph we can right click to add nodes and it is set to context sensitive by default meaning that depending on where you're right clicking or if you're pulling off of another node say right here off of actor begin overlap if i pull off of that output node other actor the nodes that are going to be available to me are going to be specific to that particular output node also everything is color coded in here so all the events have a red symbol and here are basic events begin play actor begin overlap and event tick the dreaded event tick we're not going to be using that one today but we're going to actually create our own custom event here so to do that we want to basically be able to specify when our character starts walking so i'll right click and just type custom and we want add custom event and we're going to name this to walk so anytime the event is received by this blueprint to walk we're going to make our character walk so to do that we're going to need to use what's called a timeline node so let's go ahead and pull off of this this is what's called our execution output node here we're going to pull off of that and search for timeline and we want to add a timeline so timelines are great for animating a variable a floating point an integer whatever the case may be you can go from one value to another over time and we have inputs here for play play from start stop reverse and then we have our outputs every time the timeline updates that that will output when it when the timeline actually finishes this will output so let's go ahead and double click the timeline to enter it here and from here all we need to do is create a new floating point variable so we're going to click the little f button here to do that and we'll call this path alpha and then on the timeline here for our alpha let's go ahead and frame that in a little better we're going to right click at 0 and add a key and with that key selected we're going to change the time to make sure it's zero and the value is in fact zero let's change the timeline length and we'll do that right up here where it says length we're going to set it to 10 seconds and so along our timeline we're going to right click again towards the end and we're going to add a new key and we're going to set that time to 10 and we're going to also set the value to 1. and let's go ahead and zoom in on that all right so there is our curve we're going to go from 0 to 1. now normally i'd say add an ease in and ease out here but because we want our character to move continuously at the exact same rate we're not going to do that we're going to keep it as a linear curve to do that we could simply right-click and you can choose here the different types of key interpolation if you wanted it to be more smooth to have an ease in and out ease out you could set it to auto for both so all we really need to do is move the skeletal mesh on the path by setting its world transform so to do that we're going to fire that on the update event we're going to go ahead and grab a reference to our skeletal mesh character we could do it from here or we could do it from here we'll simply drag that into the scene and choose git skeletal mesh character and then from here we're going to use that context sensitive ability of blueprint here we're going to drag off of the output node and then we're going to search for set world transform there we go and then for the transform to occur so this is moving the character we're going to do that on every update of our timeline so we're going to just drop that in there connect it up now we need to figure out where to move it and that's where our spline comes in so let's go ahead and get a reference to our spline we'll drag that into the scene and also choose get spline with this spline in fact let's go ahead and rename it here to path you'll see as soon as i rename it up here it's renamed everywhere else so we don't have to worry about doing that ourselves we're going to basically get the current location of the character along the spline and their rotation as well we want them to face in the right direction and we're going to put it all together and create a new transform that plugs in right here let's go ahead and use some context sensitive stuff here again some juju and pull off of our path and search for git spline and we want spline length that's going to give us how long the spline is no matter what we set it to in the editor and we're going to use the timeline alpha to determine where on the spline it should be so we'll go ahead and pull off of that and we're going to use a multiply note so if you just type multiply we're going to want float times float and it will grab our spline length and put that into the second input here let's go ahead and move some of this out of the way from here we need to get the location of the character uh at the distance along the spline as well as the rotation at that specific distance along the spline and we'll create our transform from that information so let's go ahead and make some more room here once again we're going to pull out of the path node and we're going to need to get the location in the rotation so just get location and then we want at distance along spline we'll plug that in right there and then we're going to get get rotation again at distance along spline so wherever he is on the spline path it's going to get that information and we're going to multiply the path alpha by the length of the spline and then plug that into our distance inputs on both of these based on the current timeline wherever you're at on that curve and the total length of the spline we know what distance he should be at and what rotation he should be at and we also want to change our coordinate space to world on both of these now you'll notice here we need to take this information and plug it all into our world transform but obviously we can't just take this and plug it in there yeah it'll convert but that's not all the information we need likewise we need the rotation information as well also it will automatically convert as you can see there sometimes it will sometimes it won't here's an example of what that does it just creates a node for me that goes from that to that but we don't want that we need to create a whole new transform that uses the location and the rotation we're going to create our transform by pulling off of this return value and we'll do a search for make transform we want to create a new one and then we also want to go ahead and take that output we'll plug that into our new transform we also want to get our rotation remember so to do that we're going to break our rotations because we only want him uh rotating on the z axis that's up and down we don't care about his x and y rotational value we just care about his his z so we're going to break this rotator by start by pulling off of it and do a search for break rotator and that gives us the three values that we need now alternatively i could right click on this and choose split struct and that will give me the three values that i need so rather than do that i'm going to recombine this instead we're going to go ahead and use the break rotator to make it a little more verbose here and then we are going to make a new rotator so let's pull off of the x here make our new rotator and then again we want x and y to be exactly the same but we're going to change our z position because he has rotated in the wrong direction we're going to set that to a value of about negative 90 that should rotate him back towards the spline now we can manually do this in here i just want to show how you can do this inside a blueprint so if you see if i rotate this by negative 90 he's now facing in the correct direction of the spline but let's go ahead and do it in the event graph so you can see how this is done we'll pull this over here and then we're going to pull off of our z so we can rotate him we're going to use an add node we're going to do float plus float and plug that back into z and remember we want to add negative 90 to his z and then we can plug that into our rotation scale will stay the same that's all we need to do now we're all set now if we want we can go ahead and make this a little cleaner by double clicking some of these lines these connecting lines here and then use these little extra nodes to make it a little more organized but we're going to go ahead and continue on for the sake of time so this should work if we compile we get no errors now what we need to do is actually fire off the walk event to do that i'm just going to do a simple one inside the level blueprint here i'm going to open the level blueprint now as long as i have selected my character blueprint i can right click in here and create a reference to him and this will allow me to work with him from him i'm going to pull out of that reference of the character blueprint and search for that custom event which was walk you can see right at the top there the call function walk and we want to do that on event begin play so as soon as this level starts up he should start walking give it a quick test and there you go he's walking along the path he's sliding like a moon walker that's because the path's really short and his animation speed doesn't match up customizing the path very easy we're just going to select our blueprint here and then we can grab the path endpoint there on the curve and then just drag that out let's go ahead and pull that over here and i can actually right click anywhere along the spline and add a new spline point and then i can move that around as well if i want to adjust the curve here i can also select the end points and then adjust those as well changing the walking speed is not actually going to work yet and that's because we need to initialize some of these variables first let's go back into our blueprint and initialize those variables we need to initialize the timeline speed based on the walking speed so let's get a reference to our walking speed and let's get a reference to our timeline and we're going to set the play rate of our timeline based on the walking speed if we pull off of the construction script execution output here and let's look for set play rate it's not going to pop up but if we pull off of our timeline and look for a set play rate you can see there that it comes up so keep that in mind so let's go ahead and connect that up and then we want to set our walking speed to our new rate and then we can compile and save and so now with that set up we should have initialized our speed properly and so if we hit play there we go so now the walking speed is having an effect let's go ahead and bring it down to something like two and there we go that looks pretty good could use a little tweaking but you get the idea so just keep in mind that if you've got a public variable and you keep changing it and nothing's happening it's probably because you need to initialize something in the construction script in this case it was our timeline speed or playback rate now we're going to set it up so that we can play additional animations so for instance what if we want him to idle when he stops walking when he gets at the end of the path we can do that with an animation blueprint so in order to do that we need to go ahead and create one so we're going to right click here in the content browser and we'll go to animation and we're going to choose animation blueprint we're going to choose this ue4 mannequin skeleton that comes with the scanned 3d people pack we'll hit ok and then we'll call this bp anim nathan all right and now we need to open that up so here inside of the animation blueprint we're going to use what's called a state machine which will allow us to go between different animations based on a variable the variable we're going to use we're going to need to create here on the side here where it says variables let me go ahead and make this full screen for you and we'll create our variable it's going to be a boolean and we're going to call this walking based on whether or not the character is walking we want to change the animation first thing we need to do is create a new state machine so we're going to right click and search for state machine we want add new state machine and we'll drag this output node here into our output pose result and we can rename this nathan state machine now we need to double click that to enter it and we'll create our different states the only two states we're going to have are idle and walk so we'll pull off of the entry point here and it will add a state and we'll call this idle and then we're going to pull off of the out the outer border of idle here and we'll add a new state and we'll call this one walk this is the connection here but we want to be able to go back and forth between idle and walk so we'll just go ahead and grab off of walk and then plug that into idle and now we have the input and the output and then if we click on the little nodes here these are the transition nodes which allow us to determine uh what it takes to transition between these two states first we need to add the animations in them so we'll double click idle and we're going to add the animation so for that we're going to go over to our asset browser and the animation we want for this idle pose is going to be right here we're going to drag that in and just wire that up okay go ahead and compile that you can see the idle animation there we'll jump back up to the state machine using the breadcrumbs here and we'll do the same thing for walk we'll go ahead and grab the walking animation wire that up compile again and then back up to our state machine so now we have our two different animations and now we need our transitions so the first one is going to be idle to walk and what do we need for idle to walk well we need to determine if the character is walking or not so we're going to drag walking into the view here and we'll get a reference to that and then for entering the state so we want to go from idle to walk can we go from idle to walk are they walking then we would just simply plug that in so if walking is true then yes you can go from idle to walk all right now let's jump back up and go to the other transition which is walk to idle and again we need a reference to walking but this time we want to not be walking so we can go to idle so rather than plugging this straight in and getting a true value of walking we're going to pull off of it and type not and so we want not boolean and then we can plug that into here so it's going to get the reverse in other words is walking false and if that's true then we can go from that state to that state from walk to idle all right and let's go ahead and compile that and save and we'll move on so the last step inside of our blueprint animation here is to go ahead and update the walking boolean and for that we need to go to our event graph and we can see an event that's already built in here that says event blueprint update animation so every time the animation gets updated we're going to specify walking is true or false so we'll drag in walking and this time we want set walking we'll plug that in here so that it wires up and then of course we need a reference to the walking variable what it's currently at so we'll get walking and plug that in right there so now whatever that variable is set to it's going to set it on every update to match whatever it was set to externally by our other blueprint so we're going to close that and then we need to add some code in our other blueprint or some nodes that will specify when to set walking to true or false so let's jump back over to that blueprint now the first thing we need to do is we also need to set it up so that our skeletal mesh is not just using an animation asset but it's now using an animation blueprint and we'll go ahead and choose our anim blueprint instance and that's going to be bp anim nathan there we go save and compile and now we need to add a few nodes in here to set that up so that he walks or he idles okay so the first thing we need to do is get a reference to that anim blueprint and we're going to do that right off of our walk event so we're going to pull that out here and then we're going to pull off of the execution and search for cast 2 and we want bp anim nathan all right so this is going to make sure that we're using that bp adam nathan blueprint and we're going to need our skeletal mesh reference here so we'll go ahead and grab him again and we need to plug that into object but before we do we need to get a reference to the animation blueprint itself so let's go ahead and pull off of that again and do get anim instance so that's giving us an instance of that animation blueprint and then we can plug that into our object and that will make sure that it's cast properly to that animation blueprint so casting is a way to change the way an object is acting it can act like something else but it's also a good way to test whether or not it is the type of object you want it to be in this case the animation blueprint and so you can see we have cast true and cast failed here and we want true of course so once we've got that reference to our animation blueprint we're going to set walking to true so let's go ahead and pull off of the as animation blueprint and search for walking there we go set walking so that's again another context sensitive thing by having a reference to that we have a reference to that variable so we'll pull this into set and we're going to set walking to true and pull that into our playback but in this case we're going to set it to play from start so now from the very beginning he should be playing his walking animation and his walking variable should be set to true now we want to set it up so that he stops and he plays his idol animation so we're basically going to do the same thing so i'm just going to copy and paste that little group of nodes here and paste it right here and we're going to do this on finished so when the timeline finishes we're going to again make sure we have a reference to that animation blueprint and we'll set walking to false this time so let's go ahead and test this out and when we get to the end he should blend into his idol perfectly there we go all right for our next example we're going to run through very quickly the creation of a multi-floor elevator system now keep in mind the system we're going to be building is a more complicated system than you might need if you need an elevator just for going from one floor to another just two floors and you don't care if the inner doors and outer doors are connected or whatever it's going to be a lot simpler this system is a more complex system allows for any amount of floors to be gone to and it has inner and outer doors that open separately at different times and and uh so this is going to be something that you would want to create once and then reuse inside of multiple projects so this is an example of the power and flexibility blueprint has for creating these types of reusable objects i've got a two-story building here we could have as many floors as we want i've already created my blueprint objects for the elevator and i'm going to be using also a floor object but first before we add them to the level and do some blueprint nodes we need to go to our project settings under edit and we're going to specify some input keys and you'll find it under engine input so we'll start by adding four action mappings here one two three four for the first one we'll call it floor one and set it to the one key on the keyboard the second one will be floor 2 set that to the 2 key on the keyboard and floor 3 for the third one set that to the 3 key on the keyboard after that we need one called press call button and we'll set that to the left mouse button all right and so when these keys and buttons are pressed they will fire these events for one floor two and press call button now we could set this up to use uh line tracing where you look at a button and press the specific button you want and that will cause the elevator to function but we don't have the time to go into that much detail today we're just going to do it real quick and dirty here using just keyboard input so an elevator is composed of both inner doors and outer doors the outer doors are on each floor whereas the inner doors are in the elevator itself now i've already gone ahead and created these things ahead of time i've got an elevator i've put together and my floor and each floor is going to have its own set of outer doors but here's an example of how you might also create a new blueprint rather than simply right clicking and that is to take objects that are already in your scene like some static mesh doors here select them all so i'll select both of my doors and then i can go up to blueprints and convert selection to blueprint class and then we would call this bp elevator doors and then we'll leave it as actor and hit select and that will automatically generate a blueprint that has the static mesh actors inside of it i have a blueprint floor object here and i'm going to drag this into the scene because this is already nicely set up and i'm just going to position it roughly where i want my doors to go so opening up our floor blueprint we've already got our two doors and we've also got a call button and a collision box now the collision box is set up in such a way that what i want to happen is when the player enters this collision box they can then press the space bar or the left mouse button i should say it'll be listening for that to actually call the elevator to this floor and when the elevator reaches them the doors on the inside and the outside will open and then it will wait there allowing them to go in now we're going to need some variables to handle all this first of all the the doors the outer doors are going to need a reference to the elevator blueprint object so they can call on it and likewise the elevator is going to need references to the floor objects to know which floor to go to so let's go ahead and create these real quick the first variable we'll add is called floor and it stores the number of this floor and we'll set it to integer we're also going to need an elevator reference so we'll type elevator riff and we're going to change this we're going to search for bp elevator webinar all right that's the object i've created to represent our elevator now we're going to make both of these public variables because we're going to specify them in the editor and then we're going to add another variable two booleans actually and one will determine if we are at the elevator and another one will be is open so are the doors already open let's be sure to save and compile okay let's jump over to the event graph and we're going to add all of our custom events so i've gone ahead and created three comment boxes here that'll allow us to organize our blueprint graph a little bit better we've got one for toggle keyboard input call elevator to this floor and open and close outer doors creating a comment is really easy we just right click search for comment and then choose add comment or you can have a selection of nodes so for instance if i take this floor variable here and draw a box around it and press c that will create a comment for it alright so let's set up our custom events so the first one we're going to need is going to be in our call elevator to this floor so we'll right click and we're going to use keyboard input for press call button if you recall when we set that up so press call button and then under open and close outer doors we're going to add two custom events and the first one will be open outer doors and then the second one will be close outer doors all right so now that we've got those let's jump over to our elevator blueprint and then we'll set up all the variables and custom events for it so here in this elevator blueprint everything is set up here we've got all the static mesh objects as well as some lights on the inside let's go ahead and turn it to unlit because the exposure's a little bit off we also have a collision box inside of the elevator and that lets us know when the player or user is inside that box they can use the elevator buttons alright so i've already set up all the variables rather than go through them step by step you can see here i have two variables that are integers for chosen floor and current floor this will allow the elevator to keep track of where it's at and where it wants to go then we have an array of floors this is going to hold all the different floor objects or the floor blueprints in the scene so that we can get references to those floors and move to them then we have our chosen floor reference and current floor reference this will contain the floor that we want to go to as well as the floor that we're currently on and then we have two booleans one to tell us if the doors the inner doors of the elevator are open or not and whether or not we're in the elevator or not with our variables set up let's jump over to the event graph and set up our custom events just like with the floor object i've got my comment boxes all set up and this shows the layout of what we're going to be doing again we're going to toggle keyboard input we also need to open and close the inner doors we need to set the chosen floor when the user presses a button inside the elevator we also need to move to the chosen floor and you can see here that i've got some subcategories in here so i've got git floor to move to move elevator update floor variables and open the doors for our custom events we're going to go to open and close enter doors and we'll create two new custom events here the first one will be let's go ahead and zoom in on that open inner doors and then the second one will be close inner doors now we're going to jump down to our move to chosen floor and we'll create another custom event here and we're going to call this one call elevator now as far as custom events go that's all we're going to need but we might as well go ahead and also add our input actions here for setting the chosen floor so those were floor one and then floor two and floor three okay so we're going to jump over to the construction script now and this time we're going to do a lot of initialization first of all we need to get a reference to all of the actor classes that are bp floor so let's go ahead and do a search for get all actors of class this is going to allow us to search through the whole level and find all the floor actors so bp floor and then we want webinar so now that we have them all we're going to store them in the floor array we'll just drag that in here and set it so we can work with that in our blueprint then we need to set the current and chosen floors so let's go ahead and drag in current floor set that chosen floor set that and we'll connect that up and we're going to set it obviously to current and chosen floor as one so we're on the first floor and while we're at it we might as well get a reference to the current floor so let's go ahead and plug that in here we'll do a get on that and in order to get the current floor we're going to use that floor array object and from that floor array that we populated we'll do a get and we want to get a copy and we want to get it by the index number here and the index number will be chosen by the current floor right so we're gonna get a reference to the actual floor object using this array and the index from our current floor now the array is zero indexed so it starts at zero so that we're going to need to subtract from current floor which is set to one so we'll do a search for integer minus integer we're going to subtract one and we'll plug it in right here and now we can get the element that we want which should be floor one and last of all we're going to set is door open and we're going to set that to false because they should not be open by default now there is actually a better way to do some of this and that is getting all actors of class so remember what this node's going to do is it's going to go through the level and it's going to grab all of the bp floor webinar blueprint objects that are in the scene and create a list out of them or an array now the problem with this method is there's no guarantee that we're going to get those floor actors all in the level order that we need and we need them to be in floor one floor two floor three floor four et cetera et cetera we need them to be organized in that order so there's actually another technique that we can use instead so let's go ahead and delete this and we're going to instead use what's called a set so for that we'll need a new variable and we'll call this floor let's just call it floors set and then we're going to change the type to our bp so that's a bp underscore floor webinar all right and so we can convert this to an array here by simply right clicking it or back again to a single object but if we want to do an actual set we're going to need to select it and then go to the details panel and click this little icon here and you'll see the set indicator there let's select that so now we actually have a set or list of these objects and we're going to make it public all right and so we'll be able to set this from the editor let's go ahead and drag a reference to that in and we need to convert it to an array so that we can use it to fill up our floor array so we'll pull off of the output node here and we'll type 2 array and that gives us the 2 array node and then we'll plug the output for that array into our floor array so it's going to grab that set from the editor window when we fill it and it's going to pop that into our array and we'll just wire that up and we can compile so now let's jump back into the editor and look at how we can populate this set okay so we need to select our blueprint floor actor in the level and there are some public variables under default that we need to set this is floor one let's go ahead and set that to floor one and we don't have an elevator reference yet because we haven't added our elevator to the scene let's go ahead and hide this blueprint and then drag our elevator into the viewport here and we can rotate that to make sure it's in the right direction all right and then we'll just position it roughly where we want it to go let's say right there is fine let's go ahead and grab our floor object here and set the reference to bp elevator webinar so now this floor object has a connection to that elevator we need to populate the set of our different floors for our elevator but before we do that let's go ahead and create all of the floors we need so we're going to create three floors here this is the first floor obviously let's go ahead and just drag that up and take it all the way up to the second floor now here's a trick if you want to get it exactly on the level of the floor there the pivot point at the bottom just press the n key and that will put it exactly where it needs to go it'll put that pivot point right on the next surface let's go ahead and drag it up even further and make a third floor and i've just got a little platform here and again we'll hit the n key and there's our third floor so let's jump back down to our elevator and let's go ahead and populate that set so we'll select our elevator blueprint here and you can see under default we've got our floors set let's go ahead and populate it we'll click the plus button here to create the first element and let's go ahead and set that to the first floor and then we'll add another one set that to the second floor and then our third one set that to the third floor all right so now we have an ordered set here of the different floors that way we can match up the first floor second floor third floor in the proper order of our array okay so let's jump into our floor blueprint now and set it all up so the first thing we need to do is to toggle the keyboard input so that the player can actually use the call button to call the elevator now we don't want the blueprint to be listening for input all the time we only want it to be listening for it when the player is inside of the collision box so we're going to select the collision box and we're going to add begin and end overlap events which you'll find at the bottom of the details panel and we'll click the plus button here next to begin overlap select the box again and also get end overlap let's go ahead and drag those into our comment box at the top so when we begin overlapping the box we want to set that they are in fact at the elevator so we'll pull that at elevator and then set that to true okay and then from here we're going to need a reference to the player controller now the player controller is what allows us to have keyboard input normally you can't do keyboard input or anything like that inside of one of these types of blueprints let's go ahead and get a reference to that player controller there we go get player controller and we're going to pull off of the return value here and look for enable input right and let's go ahead and wire up our set to that now the only problem here is that player controller was set to target but we want to rewire this to player controller we can either hit alt and click that input and it removes the wire or we can simply hold ctrl and drag it to the player controller input now normally you don't want to have blueprints like this listening for input because if you have a whole lot of them in your scene that can get performance heavy they're all listening at the same time for input and it can cause all sorts of conflicts between them you fire off a bunch of different things and that's why we're doing this only when the player is in the collision box so let's go ahead and set up end overlap now again we need at elevator we'll drag that in and set it this time we'll leave it as false and we're going to pull off of our player controller again and search for disable input again we need to rewire it from target to player controller and then we can pull off our set and wire that up to disable input so the target should be self meaning this blueprint so we're all set here so we have an opportunity to do some debugging here if you ever need to figure out if your graph is working one good thing you can do is to use the print string function so i'm going to pull off of enable input here and search for print string and what we're going to do is we're going to test obviously if we're in the box we want to make sure that it's detecting that and we'll say at elevator and then we're going to copy and paste this and this one will be not at elevator and we'll pull that off of disable input so this will tell us on the top left of the screen once we run it if we're in the elevators collision box or not so let's give it a quick test we'll walk over here and there we go it says at elevator when i'm in the box when i pull out it says not at elevator okay so let's go ahead and add the node graph to open and close our outer doors so where they have our custom events set up and we're going to use what's called a timeline to do this so we'll right click and look for add timeline so let's go ahead and double click our timeline to enter it and we're going to create a new floating point variable we'll call this door alpha now on the timeline here at frame 0 we're going to right click create a new key and we're going to make sure that time is at zero and of course the value is also going to be at zero we're going to set the length of our timeline to three seconds and then we're gonna add a new keyframe towards the end here and we're gonna set that time to 3 and in the value to 48. we can zoom in on the timeline we can compress it here with these two buttons and let's go ahead and change these keys so that they have a curve to them and ease in and ease out we can right click on them set that to auto and then of course we just need to select each key and adjust the curve that's got a nice ease out and an ease in now so i got the value for the final key here by going to my viewport and selecting the door and then moving it along the y-axis a value of 48 and that will set it to be fully open so we're going to use a branch statement here and we'll pull off of open outer doors and search for if and that gives us the branch the branch will allow us to evaluate whether something is true or false so we'll evaluate a specific variable and in this case the variable we want to evaluate is whether the doors are already open or not so we'll get a reference to that and plug that into the condition we're going to wire both custom events to the same branch and so if the doors are not open we're going to set them to open and that would mean we'll come off of false to go there and then if they have been set to open we will play the timeline forward opening the doors now if the doors are already open we'll set them to be not open so we'll leave that as false and pull the true statement into there and then we will play the doors in reverse thus closing the doors all right so from here we're going to need to get a reference to the doors themselves and we're going to use this door alpha that we created this timeline animation to control their position so we'll start with the left door we'll just get a reference to that there and we'll put the right door right here and the way we're going to animate them is we're going to set their relative location so their relative location is their location relative to their parent so we'll pull off of the first door here and search for set relative and we want location and then we'll do the same thing for the left door again set relative location okay and then we're going to wire these up to the update function so we'll pull that out of the timeline and then we'll connect this one here but keep in mind that the doors should be opening in opposite directions you don't want them to both go in the same direction so we're going to negate the value that we use to control the other door the left door so to do that we'll search for a negate and we're going to negate this floating point value from the timeline and we'll plug that into the other set relative location all right so the alpha is only controlling a single floating point value but the locations are obviously x y and z and we just need that single value on the y axis so that's where the door is animating on so we can right click on this and split this open and it will do the same thing here split struct pin all right and so now we can come off of our door alpha and we'll plug that into the y and then we'll do the same thing for our second relative location and we're going to plug this into the negate function first and then that goes into the y now the x and z values they should remain the same but we need to make sure they are matching to what the viewport actually has so if i were to select this door we can see that the x value is 20 and the z value is 107 same for the other door so let's go ahead and jump back over here we'll set our x values to 20. in other words we don't want it to move on the x or z we just want it to move on the y and that was 107 on the z all right that should be it now if you want to clean up some of these lines we can actually double click a line to create a new point and then drag that point out of the way here so instead of going under that node we can actually make it go around the node so we need to make sure we compile our script and then we can jump back into the editor and let's open up our level blueprints and i've already created a little sequence of events here on begin play we're gonna wait about five seconds so we can walk to the door and see it then we'll fire off the open outer doors event we've got a reference to our floor object here we'll wait for another four seconds and then fire the closed door event so let's go ahead and check that out there we go the outer doors are opening and then they should close back inside the floor blueprint we're going to now set up the call elevator to this floor node graph obviously again we have our press call button input here and basically what we're going to do is get a reference to the elevator and use its call elevator function so we'll get that reference we'll pull off of this and type call elevator so we could naively just wire this right up here and as soon as you press that button it's going to call the elevator regardless of where the elevator is but we're going to need to add some graphs in between here to make sure it does everything the way it should first of all we're going to test to see if we are in fact at the elevator when we press the button so we'll do an if statement and then the condition we'll use is at elevator after this we're going to do another branch to determine if the current floor that we're on is already the chosen floor or not so if true if we are at the elevator we'll do another if statement and we're going to need the current floor and we're also going to need the chosen floor which comes from the elevator so when you press the elevator button to go to a floor that's where that comes from so we'll get again an elevator reference and we'll pull off of that and look for chosen floor and we want get chosen floor now we're going to test to see if they are the same or not and we're going to do that using a not equals so we'll pull off a floor and search for explanation equal or not equal integer and it will plug in chosen floor to the bottom input and this will tell us whether or not they're equal and we'll plug that into our condition so now we have two options here true or false let's start with false in other words if the chosen floor and the current floor are in fact the same we're going to pull off of the false here and we'll do open outer doors and that's going to fire off the open outer doors event here inside of this blueprint but we also want to open the inner doors of the elevator so we're going to pull off of that and we're going to do a little delay for about half a second this way they don't open at exactly the same time which is something you see in real world elevators and then once it's completed we can open the inner doors we'll need a reference to the elevator again let's go ahead and just pull it off of that one and search for open inner doors there we go so that will fire off the event inside of the elevator to open its doors now before we actually fire off the call elevator event on true we want to set the chosen floor from the elevator to the current floor and we'll go ahead and just pull off of the elevator reference again and we want to do chosen floor and this time we're going to set the chosen floor and we're going to set it so that it matches the current floor now we can pull off of the true statement here plug that in there and finally this can plug into our call elevator event all right so the floor blueprint is completely set up now we can compile it everything is green we're good to go let's jump into our elevator blueprint and as before the first thing we want to do in here is to toggle keyboard input and we're going to simply copy and paste from the floor and we'll just go ahead and grab that and then paste it right over now we do want to change one thing and that is the variable that's being used we're not at the elevator we're in the elevator so let's go ahead and plug that in here on begin overlap we will set that we are in the elevator to true for end overlap we will set it to false and next we're ready to set up open and close inner doors once again we can actually copy and paste most of this is going to be very similar so going back to the floor blueprint let's just grab this graph here everything except for the events and then copy that and we'll paste it right here okay so we're gonna wire our custom events up to the branch again and we're going to change the variable here from is open to is doors open probably could use the same variable name here though actually and of course we also will have to change the set operations here to our doors open variable and false goes in here we'll set the doors to open and play forward likewise when true we will set the door open to false and play in reverse thus closing the doors now let's make a little room here because there's a couple of other things we want to do here after we set the doors open to false and that is we're going to need to close the outer doors on the floor blueprint so for that we'll need a reference to the current floor and then we can close the outer doors close outer doors remember that is our custom event and let's wire that up here and then after that we're going to do a little delay of about half a second and then we can wire that to our reverse okay and now let's jump over to our set relative locations and of course we'll need to use some different door static meshes here the ones we want we can drag in from our component tab here so we want our right door and then our left door and we can plug that into target in the case of these doors if we jump over to the viewport you're going to see that they actually are a little different the way they're set up so if i select this door the axis that i need them to move on is actually going to be the x axis and the y value on these doors is at a value of 63 while z is 0. so we need to keep that in mind when we're setting this up we're going to set z to zero on both of these doors and we want to control the x axis using our timeline so we need to change that let's go ahead and break this connection here and set our y to 63 on both doors all right and now we should just need to update the timeline information again if we go back to the viewport we're going to notice by selecting this door that it starts at a value of 73 on the x so we'll need to keep that in mind instead of starting at a value of 0 our timeline's first keyframe here needs to start at a value of 73 and we want it to end at a value of 129. all right everything's set up in our timeline we should be good to go next let's set up our input for our different buttons the floor one two and three buttons in here we're basically going to set the chosen floor of the elevator based on the button press and then we're going to check to see if the current floor is not equal to the chosen floor if true we're going to check to see if the doors are open and if true we're going to close them so we can grab our chosen floor variable here and we want set let's go ahead and copy and paste that a few times all right and we're gonna use this first one for floor one so we're setting it to one second one will be set to floor two and the third one obviously to floor three we need to wire those up okay now we're going to wire all three of these to our first branch and floor three and the first branch will be checking whether the chosen floor is not equal to the current floor so we'll pull off of chosen floor search for not equal plug in current floor to the input on the bottom and then plug that into our condition now if true we'll do another branch and this will determine if the doors are open or not now if the doors are open we will close the inner doors here's an opportunity to have a look at another debugging option and that is using simulation on your blueprint if you click the simulation button here at the top and then we go ahead and play this in the editor anytime that we do anything that is intercepted by blueprint we'll be able to see the flow of action in here so we'll go up to the elevator and let's go ahead and open the doors and then when we're inside the doors we're going to press 2 for the second floor and pay attention to the blueprint window there and watch what happens so it was really quick but you could see clearly that lines lit up to let you know what path it was going down so it's another great thing you can use to debug your node graph to see if it's using the right nodes going down the right path when you expect something to happen so likewise if i hit the three key now it's not going past the second branch on that because the doors are currently closed okay captioning not a node called available component 2. so i'm just going to right click here and search for move component 2 and this will allow us to move the entire elevator to a specific location so we can see here we've got the target's relative location and relative rotation and we're going to need both of those right so we've already got our call elevator event here and before we can move the elevator we need to figure out what the chosen floor is and we're going to get that chosen floor from the floor array so let's go ahead and pull a copy of the floor array in here and get that reference and then we'll pull off of that array and search for git and we want get a copy so we're going to use chosen floor to figure out which element in that array we need but keep in mind that arrays are zero index meaning the first element is zero the second is one the third is two and so forth so our chosen floor value for the first floor is 1. so anything above that is going to be 2 and 3 and so forth so we need to subtract the value of 1 from that so we'll just search for minus and we want integer minus integer and it's already defaulted to a value of 1 and then we can plug that into the index for our get so now we'll get the proper element based on the chosen floor with that information we need to set the chosen floor reference so this will actually set the reference to the blueprint actor in the scene and we can wire our custom event to call the elevator into that to move the elevator the first thing we're going to need is a reference to the actual shared root of our elevator here which contains everything underneath it and we're going to get the current world location so get world location and so we're going to move the elevator based on these coordinates here but the only thing we really care about is the z-axis up we want to move the elevator up so we want the x and y to stay the same as they were from the beginning so we're going to split this struct open here giving us access to those three values and we'll do the same here and then we're going to just plug the x and y directly in so that they stay the same now we're also going to need a reference to our relative rotation we don't want it to rotate or anything like that now we can try to plug in our shared route straight into that but you'll see that it doesn't work so we need to convert it first to a relative rotation so by letting go i can search for relative rotation and we want get relative rotation and then we can plug that in right there all right so that ensures the elevator or will be in the same x and y position and have the same rotation now we need to specify the relative z location we're going to do that using the chosen floor reference so we'll pull off of that and search for default scene root there we go we want to get that default scene root now the way i know that i need default scene root is we jump back over to the floor blueprint here and in this blueprint we can see that the root object is called default scene root so now that we have the default scene root we can pull off of that and get world location again we need to split that struct open and all we really care about is the z so we're moving it on the z axis we can also set an ease in and an ease out so the elevator gently moves up and then gently comes to a stop and now we also need to not forget to set up our execution flow we want to plug that into move now one more thing we need to do is we need to specify the component that will be moved so again we'll pull off of shared root and plug that into the component input now we also want to specify the time that we want that it to take for the elevator to move that we could do something complicated here and tie it to the distance the elevator is moving and stuff but just for the sake of simplicity and the time i'm just going to set that to 10 seconds so it'll take 10 seconds no matter which floor it goes to for the elevator to get there all right so next up we need to update our floor variables so everything is correct so we're going to get current floor and choose set current floor and we're going to set it to the chosen floor and then we'll wire up completed so when the move is complete to that and then after that we need to update the current floor reference so we'll grab that and choose set current floor reference and once again we're going to need that array so let's just copy this code over here and then paste it down here now we need to plug this in to our current floor reference however this is currently wired up for chosen floor but we want current floor all right and then last of all here we can open the doors so for that we'll pull off of our set execution flow here and search for open inner doors and then about a half second later so we'll add a delay set that to about 0.5 seconds and then we can open the outer doors and of course for that we're going to need the chosen floor reference and we'll pull off of that and open outer doors and then of course we need to wire that up all right let's compile and save everything is green okay so there's just one last little bit we need to set up here and that is this box here where i've specified if current floor does not equal chosen floor then we'll call the elevator to the chosen floor and we're gonna pull this off of the timeline's finished output so let's go ahead and drag that over here and we're going to branch so we need to first test to see if the current floor is not equal to the chosen floor so let's grab a reference to current floor and chosen floor and again as usual we'll search for not equal wire that up and then plug that into our condition and if this is true we'll fire off a short delay of about one second here and then when done we will call the elevator and of course that's referring to the call elevator event here inside of our elevator blueprint when the door animation completes whether they're opening or closing it'll test to see if the elevator is on a different floor and if it is it will call the elevator to that floor and of course the other option is when you're outside of the elevator the blueprint floor object will call the elevator and all of this will fire all right so that should be it and we can now test it all right we'll play in editor and walk up to the elevator left click opens the door and then let's go ahead and go to the third floor so i'm gonna press three doors closed elevator begins moving and i'm on the third floor now let's go back down to the second floor i'll press two there we go this is all the time we really have today but we could take this a bit further and feel free to do it yourself we could do things like making the interior buttons light up when they're pressed for a given floor i'll give you a hint you can do that with dynamic material instances inside of blueprint you could also change the interior led to say what floor it's on as the elevator moves from floor to floor we can add an audible ding sound when the elevator reaches a floor so the user knows that the elevator has arrived we could also set up all the buttons to use all the call buttons and floor buttons to use line tracing blueprint functions instead of keyboard input to make it even more interactive and we can even have them highlight in a different color when you're looking at them all right so that's going to do it for today this is about all the time we have it's a lot to cover i know but we're going to be posting the video later and feel free to re-watch it as many times as you want and if you have any questions or have issues getting it to work feel free to post comments on the video and i'll be monitoring it and i'll definitely be happy to answer any of those questions and comments that you have so thanks for watching you
Info
Channel: Unreal Engine
Views: 8,887
Rating: undefined out of 5
Keywords: Unreal Engine, Epic Games, UE4, Unreal, Game Engine, Game Dev, Game Development, Blueprints, visual scripting, unreal webinar, Variant Manager
Id: UO-z6snZLV8
Channel Id: undefined
Length: 68min 42sec (4122 seconds)
Published: Mon Dec 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.