Getting Started With Blueprints - Unreal Engine 5 Beginner Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] do you want to build interactive experiences with unreal engine 5 but you're not sure where to start with blueprints artists beginners and just about anyone are going to be able to create custom functionality for their games or apps in no time in this video we're going to be breaking down exactly what blueprints are and how they can be used and get you started with writing blueprints for yourself understanding fundamental flow control variables logic and more by the end of this video you will have built two scripts of your own including a toggleable flashlight and door that automatically opens when a player gets close by while this video is aimed at beginners i definitely recommend you go ahead and check out my unreal engine 5 world building video first so you can get to grips with using the engine and building your very first world the link for that is in the description down below before we get into writing any code as part of this video let's start off by talking about what exactly blueprints are blueprints is a method of writing code visually using lines and nodes as opposed to traditional code like c plus where you're going to be having code with your syntax and quite honestly the learning curve for that is incredibly steep blueprints can be just as powerful as c plus giving artists and just about anyone the ability to quickly prototype their games and their experiences myself i have used blueprints to prototype a lot of my game projects or client projects because it can be done so quickly unreal engine 5 utilizes blueprints for a lot of things and it's not just there as like a prototyping language it's actually used to drive a lot of functionality where c plus isn't for example things like artificial intelligence and user interfaces just about anything can be driven by blueprints blueprint is used all throughout unreal engine 5 and in some cases is actually used where c plus shouldn't for example things like user interface and artificial intelligence more often than not this is going to be powered entirely with blueprints now with that being said blueprints can do a lot more than that it can do almost as much as c plus this can be used for creating sort of core gameplay functionality it can be used for sort of multiplayer experiences it can be used for inputs it can be used for console stuff it can be used for so much most importantly though with all of this blueprints is incredibly powerful when it comes to prototyping a lot of small startups don't like having the overheads or big teams full of c plus plus programmers to very quickly rapidly produce these prototypes more often than not what we have in the games industry is we have game designers and artists a couple of those will work together to build these whole prototypes using just blueprints and with that they most likely won't actually have any sort of c plus plus programmers getting involved in that prototype and that is because we can do things very quickly with blueprints from a logical view then let's take a look at exactly how blueprints are going to work so we have a better understanding as we dive into this video and start using blueprints for the very first time so just like c plus plus blueprints is an object-oriented programming language what i mean by that is you're going to have actors and objects and with that you're going to be able to reference the properties whether that be as sort of variables or creating things like functions to change all of those everything is object-based and inside of unreal engine as soon as it goes into the scene everything or every one of those objects becomes an actor with that let's go ahead and talk about how these blueprints are going to look so we're essentially going to have a series of nodes which determine our functionality and with all of these these are all going to be executed in series so we're going to have the first node the second node the third node and so on just as if we were going through multiple lines of code and between these nodes we are going to have lines and that is called our execution path now with this execution path and our nodes these can only be triggered or executed when called by what's called an event an event could be anything from a player pressing a button on the keyboard or it could be a player walking into a certain area in the level once they do that once they activate that trigger anything that's hooked up to that trigger is then going to be activated along the execution path in series just like i said you'll get to see all of this in action as we go through this video building scripts for ourselves before we dive into blueprints i wanted to take a moment to shout out our sponsor for this video and at our c plus plus programmers out there learning c plus programming is not easy and visual assist is there to help you along the way visual assist is a visual studio plugin that helps unreal engine c plus plus programmers write and navigate their code easier one major benefit of having it installed is how it can help you write your scripts it helps you to correctly write your syntax and directly understands unreal engine objects so you can get straight to writing your scripts picking up any mistakes along the way some of you see plus plus programmers may be familiar with the built-in visual studio plug-in that does this called intellisense now with this it only really understands c syntax it doesn't really understand unreal engine objects visual assist was built with unreal engine developers in mind if you're working on a large project you'll know you can't use intellisense as it just completely grinds to a halt trying to pass all of your code with visual assist you get all of those benefits no matter the size of the project if you'd like to learn a little bit more about visual assist be sure to check out the link in the description for now though without further ado let's go ahead and dive into blueprints okay now that we're inside of the unreal engine project browser the very first thing that we need to do is we need to create a project which supports blueprints to do that inside of our unreal project browser we have two options we have blueprints and we have c plus and these are very different and as we go through this demo today i want you to use the blueprint sample as it does not include any traditional c plus code i'd also like you to use the third person template setting your target platform to desktop and maximum quality with starter content enabled go ahead and give this a name and then we're ready to dive into unreal okay now that we're inside of unreal engine let's go ahead and take a look at our most simple type of blueprint that we're going to be able to find in here and that is our character blueprint to access this we're going to go over to our content browser and then we're going to go to all content third person and blueprints inside of here we are going to find a file called bp underscore fed person character and if we hover over this as well we can see this is a blueprint class with this blueprint if we double click on this we can open it up and we can start familiarizing ourselves with the blueprint scripting interface and this is it so first and foremost we have our event graph in the middle here where we can see our code or our visual code and this is going to be made up of those sort of events and those execution lines and then our different nodes and variables that we talked about earlier what we also have in the top left hand corner is our components panel where we can see all of the objects that are within this blueprint class so for example if i go over to the viewport we can see this is made up of first and foremost a character mesh so a model a 3d model we can also see we've got a camera and we can also see we've got a character movement component but most importantly with all of this all of your components in the top left hand corner here are objects that you can reference in your code what we also have in here is any character related variables in the variables tab down in the bottom left here right now we can see we have got variables for our turn rate and we've also got some stuff related to the camera as well we are going to be creating our own variables later on but any variables that you need to have within this class are all going to be located in the variable tab down here what we also have is the details panel on the right hand side where we can see any of the details for a specific object or a specific component so you can see here if i select my character movement component here i can see things like my gravity my acceleration my mass my ground friction all of the information relating to that movement if i select something like my camera i can then see all of the details for that camera so that's how we can change the default properties of a component here if we wanted to change the properties in real time during the game that's where we're going to be setting all of that with a code all of the stuff on the right-hand side here is purely just your default values with all of that being said let's go ahead and move on to the next section okay now that we know what a blueprint looks like let's go ahead and take a look at some of the other different places that we can access blueprints so we already know that we can access blueprints inside of our character blueprint where we've got all of the components and pieces that make up the character you can also have blueprints in the level where essentially everything in your level is a component or an object that you can edit to access this we can do this by going up to the blueprints icon in the top left hand corner above the viewport and then inside of here we can press open level blueprint and this is going to take us to a very familiar editor which is very similar to the one that we saw before inside of here we can again see we've got our main event graph we can also see we've got our variables and we can also see the details panel for this now with this the big key difference we're going to see here with our level blueprint is we cannot see all of the different components listed out if you want to see that you can see that as part of your world outliner in the top right hand corner of our unreal engine user interface but essentially if we wanted to get a reference to something we'd simply select it in our world outliner or in our viewport and then from there we can then create a reference to it in our code that is how this works now a big thing when it comes to our level blueprints is any code that we put in our level blueprint is only going to work in that specific level so you could not create your code for a lot of your mechanics in one level and then take all of that over to the next level if you were to do that you would instead need to put this in its own blueprint class which we'll talk about in just a moment or in the game mode or the character just something that is going to persist from one level to the other the level blueprint is 100 level specific with that being said let's go ahead and take a look at the last blueprint that we can do which is a blueprint actor okay we're now going to move on to taking a look at blueprint actors these are standalone blueprint classes where the objects are contained within and can be placed in any level and any of those objects contained within this specific blueprint class can be edited by that blueprint using blueprint code to create a blueprint class it's really straightforward right click and go to brew blueprint class then we're going to be creating a blueprint class of the type actor if this was a character or something else then you could use the character because a blueprint character is also one of these classes in the sense that all of the components are held within but we're just going to work with an empty template for now so just actor and we're going to give this the name test and if we open this up we then have our blueprint actor interface and it's exactly the same as what we saw a moment ago with the character in the sense we have the viewport so we can see the physical representation of this blueprint we've got the list of components in the top left hand corner we've got the list of variables and the details for any selected objects in here we can add components to these really straightforward all we need to do is just go up to the add button in the top left hand corner and then we can add components such as point lights and then with the point light selected we can simply go in and start changing the properties now blueprint classes are going to work a little bit like prefabs in the sense that you can add multiple objects lights and things together and then reuse them throughout your level for example with this i've just added a point light into here and i could add another point light into into that if i wanted to and then in my viewport i can move those along so we have a group of two point lights in a blueprint i could then drag those into my scene and we can see we can very quickly start getting these grouped assets with all those properties into our scene together which is quite nice really straightforward and really easy to do but most importantly with these blueprint classes we can reuse that same functionality over and over again and we can put this into any level so now that we know how blueprint classes work we know how level blueprints work in the sense that we have levels and we have actors within that that we can get a reference to and we also know with characters it's very much the same as the blueprint class just the differences it's more character related stuff and the inputs let's take a look at how we can actually get started writing blueprint code okay let's move on to getting started with blueprints and writing it for ourselves now one fundamental thing that i need to introduce you to before we move on to writing any actual code is the concept of variables and the different types of variables that we have available to us variables are essentially just data storage variables are going to be things for like health the number of coins the player has all of this needs to be stored as data and that is going to be a variable now a variable can come in many different forms that could be either a number it could be a piece of text or it could just be an object a an object can also be stored as a variable so there's lots and lots of different types of variables we can play around with and in just a second we're going to be breaking down what each of those are and how you can create them to do this we can go to plus variable and with this we can now choose a variable name and we can call it something like health but most importantly what we have next to this is the option for the variable type and we've got many different options here and i'm going to break down all of the important ones for you the first one is a boolean booleans are just true or false values that is are the lights on or are they off so lights on is true lights off is false the next type that we have is our integers an integer is just a number a number that is a whole number so 10 11 12 that would be an integer so we could store the health as an integer really straightforward what we also have though is floats floats are numbers just the same however the difference is we can actually have decimal values so we can have 1.1 1.2 1.3 and so on so any kind of logic where we need to have decimal places we're going to be doing that with a float the next few types of variables we've got here are all related to text so we've got names strings and text which are just essentially text data and there's different types for names or if it's just something that's being displayed on the screen and so on we're not going to go into those too much right now the one that you will see the most is going to be a string but we'll use that a little bit later in this video then lastly we also have vectors rotators and transform which all work in very similar way a vector is essentially made up of three floats now a vector is going to be used for things like this scale or the location where we have three different values your x your y and your z and if i go ahead and change this to a vector and hit compile you can see that we've got an x value a y is that value and a z value and we can change all of those independently in a similar fashion with our rotators it's very similar if we hit compile we can see again we've got this rotation but it's on three axes so we've got x y and z so just allowing us to store three pieces of data now with rotation we should always use a rotator whereas with anything else where it's just three pieces of data we can use that vector lastly what we have is our transform which is actually made up of location rotation and scale so there's actually nine different floats in here that we can see so that's our main variable types as we go through this video and we start making some of these demos the flashlight and the door we are going to see some of this come to life with all of that being said let's very quickly see how we can get a reference to these variables so we can use it in our code very straightforward all we need to do is simply drag out from the variable and then press get we can also set the value of that variable with code again we're going to be doing that in just a moment but now though let's go ahead and move on to that breakdown of the different types of blueprint nodes that we have and we can then get started writing them okay so now that we know what variables are we can get to writing some code for ourselves so we're going to start off by writing some very simple scripts so first and foremost if we open up our test blueprint that we just created inside of here we've got our components let's start tweaking some of these components using code to do this i'm just going to go ahead and get a reference to that point light and with this i can then take a look at changing any of the properties using code to do that we just drag that point light into our event graph and then with this we can do things like get the properties or of an object or alternatively we can set the properties of that and that's how we're changing things with code and then we're also using blueprint in conjunction with that to get the behavior and the logic to to do all of this so let's say we have the player when they press the f key or something like that they want to toggle a light like a flashlight all they need to do is just set things like the visibility and with that they can then set the visibility of this point light to the value of this boolean or this variable which is just true or false so we could set this to true or we could set this to false very simple scripting there we could set things like the intensity again and all we're doing is just feeding variables into this so there's lots and lots of things we can do with this but the important thing to take away from here any of this object's properties we are going to be able to change in blueprints that is how we're driving our functionality we're just changing object properties so with that being said let's go ahead and take a look at writing some scripts so we have got this event here which as we know is essentially just a trigger when this event happens run some code with this event it's for when the game begins playing it will then execute any code from this so when the game begins playing i'm going to take my point like here and i'm going to change the intensity so set intensity to a really high number like 10 000 and from that trigger i just drag out from the execution pin and put that into my execute what i need for my changes to take place is to press the compile button in the top left hand corner and with this now what's going to happen is we've got these lights which are relatively low intensity and then if we press play you can see they've become really bright because that code has happened so let's see that let's just add a couple of zeroes to that and press compile so we can really see this happen event beginplay which is as soon as i press play we can see that intensity gets changed that is the very basics blueprint we have a trigger which is called an event and then we have our blueprint nodes which actually changes stuff with this and we can do so much with this it's not just changing properties of lights it's spawning objects it's playing animations and all of that some very simple code here what we can do from here is we can start moving on to flow control which is going to determine which code should be ran and when to add a little bit of logic to it which is going to help us bring all of our blueprints to life okay so we know how to work for variables we know how to make some very basic scripts now let's take a look at how we can control the flow of our code in this video we're only going to be covering the branch the sequence node the gate and the flip-flop node there is lots more flow control out there such as loops and if you'd like to learn a little bit more about that you can check out some of our other blueprint tutorials to learn all about it but for now this will take you through everything you need to know to start creating some simple scripts so starting with the first piece of flow control that is the branch and arguably that is the most important this is essentially the equivalent to creating an if statement in traditional code we can check to see if the value of something is equal to that and if it is do one set of code if not do another set of code and this is incredibly powerful and these conditions can be any variable for example that could be check to see if the light visibility is true or check to see if the player health is above a certain amount or below zero and we can do different actions depending on that so really really powerful stuff so let's go ahead and use the branch node to create this all we need to do is hold down b on the keyboard or alternatively we can just right click and search for branch and you'll see that underneath flow control so what we're going to do is we're going to take this trigger that we've got event beginplay and with this what we're going to do is we are going to check to see if our health is less than one and if it is it's going to print a string that says you are dead so let's take our health variable and if you haven't got one already just go ahead and create it and then we're going to set this to an integer so it's a number and then compile so we can change this and we're going to set the health to 100. so we're going to set up a very simple condition here which is get a reference to health by dragging it and then we're going to from our condition we're going to check to see if it's less than and the way i did that is just use the less than symbol we could do less than or we could do greater than or we could do equal there's lots and lots of stuff that we can do in here it's entirely up to you but we're just going to check to see if it's less than or equal to zero and if it is we're just gonna tell the player they're dead so let's do that so we are going to see if it is less than or equal so add that in and if our health is less than or equal to zero what we're going to do on true we are going to run a print string that says you are dead and on false we are going to run a print string that says you are alive and then we're going to go ahead and hit compile minimize this press play and you can see there it said i am alive and it said that because we know our health value here is a hundred if we set this to zero and then press compile we can then see that it says we are dead now if you had def animations and def particle effects you could definitely play that using code but this is a very simple demonstration of what the branch node can do so really really useful stuff so now we know how to use the branch let's go ahead and take a look at how we can use the sequence node so right now all of our code is going to get very messy when we start adding lots of stuff in here if we want to make sure that our code runs in a certain order we can use this sequence node with this it just has one execution pin and from there we have then zero then one and if we wanted to we can add points for then two and three and it's going to run all of the code from this in sequence so rather than one big long line of code we can have multiple lines here which is a lot easier to read and understand so i could tell it to print a string that says one and then on the next one i could tell it to print a string that says two and then just do the same thing and you're going to see if i do this for each of these and set this to free and then press compile it is going to run those in order there we can see that happened multiple times that's because i've got multiple versions of this actor in the scene so if i just go ahead and delete some of those so it's just the one we can see it said one and then it said two and then it said free so really really easy sequencing here with this node the next node that we're going to take a look at is our flip flop node what this is going to do is very simple and we're not going to do a demonstration for this but it's essentially going to toggle or alternate between a and b outputs so imagine you've got a flashlight and you want to be able to turn it on and then you want to be able to turn it off what we can do with that is we can just have set visibility on on the a and then set visibility off on the b but all coming from that same button it's just one button and you just want it to alternate that is the flip-flop really straightforward and we are going to be using this in just a moment as we go into the flashlight demo the last node that i wanted us to take a look at is the gate node with the gate this is another really important piece of flow control with this it works just like a real gate you can only go through it when the gate is open if the gate's closed you cannot so with this we go we have an execution pin that goes into enter but then with this it's going to start closed by default unless we tell it not to and with this if they exit that gate it then runs the rest of the code so what you could do here is if they've turned the flashlight on or if they've got close enough to the door we open the gate and then again when they press a button on their keyboard they can press enter and providing they're close enough it then opens the door for them and they can turn and go through that code again i'm not going to go into a demonstration for this we will get to use this as we learn blueprints but with this have a little experiment with some of the different code pieces that you have but with that being said what i want to do now is move on to two practical demos where we create some really quick and easy scripts the first one being a flashlight and the second one is a door that actually animates and opens for this next piece what we're gonna do is we are going to create a very simple flashlight inside of our character blueprints so you can see how inputs work and how we can then start controlling actions within our game to do this go ahead and open up your third person character blueprint if you can't find this it's located under content third person blueprints and bp underscore third person character now let's start setting up our flashlight the very first thing that we need to do is actually create a physical light within our components to do this go up to add and then we're going to be adding in a spotlight and with this we can now control the location of the spotlight so i'm going to put it just in front of the hands here and i'm also going to turn the intensity up to a slightly higher value now with this if we go ahead and hit compile and hit play when we start moving around our character you can see that flashlight is actually there already it's following the character which is perfect so all we need to do is set up the functionality to turn that light off and then turn that light on again to do this we're going to go into our light and we're going to make sure it turns off by default so set the visibility under rendering to untrue with the spotlight selected and then in our event graph we can start working with inputs to activate different actions when the player presses a button in this case if they press the f key on the keyboard it's going to turn that light on or off so if we search for f and then scroll down until we get to our inputs and what might be a little bit easier is if you type in f input we are going to be able to see under keyboard events we can take and create an event for f for when we press this so essentially what we're going to be doing from here now then is we're just going to be taking a reference to this spotlight and we are going to simply use a little function called toggle visibility and then if we put this into our pressed hit compile and that visibility state that we just played with earlier is going to change so press it once and the flashlight's on press it again and it's off on off on off really really simple if you don't have toggle functionality for what you're trying to do what we would do is simply use the flip-flop node that we talked about earlier and just have spotlight and just do set visibility and set it to on for our a and then copy and paste that set visibility and set it to off for our b and make sure the target is set to the spotlight the target is essentially just the actor or the object that's being referenced go ahead and hit compile and save press play and we can see this come to life what you might want to do just in your demo is take your directional light and turn the intensity of this down to a value like 1 or even 0.5 so it's a little bit darker so you can see this and then press f and we can see our flashlight is working perfectly that is the end of our first demo and should get you on your way to creating some simple gameplay mechanics for your character for your game or your experience what we're now going to move on to is creating a door that's going to open and animate open when we walk near it and this is going to be done in a slightly different way so this is going to be in a blueprint actor because i want to have loads of these doors if i want to so i'm going to right click in the content browser go to blueprint class and i'm going to use the type actor which is just empty just like we showed you earlier and then we're going to set this to door when we open this up we're going to start off by adding in the physical components first for us that's actually going to be two pieces a door frame and a door but both of these are 3d models or as unreal engine calls it static meshes so i'm going to add a static mesh into my components and then under my static mesh i'm going to search for door and you can see we've got sm underscore door and we've got someone's called door frame the first one i'm going to set to door frame and we can see we now have our door frame and i'm going to add another static mesh here and with this one it's going to be sm underscore door and with this i can then just drag and make sure my door is in the frame correctly there hit compile and minimize that with that done we now have this door blueprint here and like i said we can have as many of these in our scene as we like and if there's any code each of these are going to have that code applying to it which is really great so let's go ahead and start setting up the functionality for when you get close to this we're actually going to open the door the first thing we got we're going to need then is some kind of collision and we're going to be using the box collision and with this box collision we're then just going to scale this up so it covers a nice little area of the floor in front and behind this door now heading over to our event graph what we can do is we can start creating an event using event actor begin overlap here so when they walk on any object near this we can execute this code so on event begin overlap what we're going to do is execute and we can just take this door and we can set actor or set rotation of this so set relative locat rotation and we can set the new rotation to 90 degrees which is just open so go ahead and hit compile and save and again if we press play walk near one of the doors you can see it opens really straight forwards some really simple code and each of these are individual and i can walk up to these and i can open each of these individual which is great so we can now take this a little bit further and we can get it to actually close after a number of seconds so after a delay of two seconds we're just going to set that relative rotation back to zero and hit compile make sure your target is the same door as before hit compile and then let's hit play with this door opens we can walk through and then it closes again and we can do the same thing for each of these doors really awesome so we've got some really straightforward and really nice functionality here let's take this one step further now and animate the door's rotation using code and to do this we are going to be using the timeline node so we're going to scrap this code here the only bit we're keeping is our begin overlap and we're going to right click and add a timeline and then with this we're going to put our execute from this into our play with the timeline we're going to give this the name door animation and you can see i'm just setting this up in the details panel in the top right hand corner now double click on our timeline to open it up and we're going to create a track and that is essentially what a timeline is it's just a key frameable track that we can animate different properties on in this case it's going to be our rotation so i'm going to press plus track and i'm going to use float track i'm going to give this a name door rotation because that is the value that we're animating here now on this i can add a new key to this really straightforward just right click and add key to cut float and what you're going to see appear here is the time and the value the time is going to be 0 and the value at zero is going to be zero so as soon as this animation starts the door's closed what we're then gonna do is add a new keyframe and we're gonna set the time to two seconds and we're gonna set the value of this to 90 degrees so what's going to happen between that first keyframe we just added at zero and between the second keyframe at two seconds it's going to move over to 90 degrees and you can see this if you press zoom to fit horizontal and zoom to hit vertical with these two little icons here with that done and i know i went a bit quick there so feel free to sort of take some time and go back on the video what i can do is from this update which is also an event essentially i can then take my door and just like before i can set relative rotation and i can take this door rotation here and put it into my z-axis to control that spin because this is a rotator it's slightly different to what it's expecting i can actually right click on this and press split struct pin to take a float and put it into just that one axis press compile save and from here we can press play walk up to the door and it animates open that is great and i can do that for each one of these doors i hope you have enjoyed this introduction to blueprints you should be at a point where you're comfortable understanding the flow and the logic of blueprints and are able to research additional nodes and functionality to bring your game and your experiences to life if you'd like to know a little bit more about unreal engine 5 be sure to subscribe for your weekly dose of unreal engine training over on this channel if you have any burning unreal engine 5 blueprint questions be sure to go ahead and check out our community discord server with thousands of like-minded unreal engine users just like yourself we're going to be releasing an in-depth seven-day course where we're going to be going into detail how you can use blueprints to create the functionality for your game everything from artificial intelligence user interface everything is going to be covered so as soon as we release that be sure to go ahead and check out our website again the links are in the description down below that's it for this video though i hope you have enjoyed it as always stay awesome keep creating fertis signing out
Info
Channel: Virtus Learning Hub
Views: 64,506
Rating: undefined out of 5
Keywords: virtus, unreal engine 5, unreal engine 5 tutorial, unreal engine 5 beginner, ue5 tutorial, unreal engine, ue5, ue5 beginner tutorial, unreal engine 5 tutorial beginner, unreal 5 tutorial, unreal engine 5 introduction, virtus unreal engine 5, unreal engine blueprint tutorial, unreal engine blueprint, blueprints, game engine, unreal engine 4 blueprints for beginners, unreal engine 4 tutorial, beginner blueprints tutorial unreal engine, blueprints for beginners tutorial
Id: 0yZVkF9rLgg
Channel Id: undefined
Length: 41min 47sec (2507 seconds)
Published: Fri Jul 01 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.