How to Create a Game in Unreal Engine 5 - UE5 Beginner Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone if you want to create games in Unreal Engine 5 then this video is for you in this tutorial you will go from knowing nothing about Unreal Engine 5 to creating this game right here the goal is to destroy all the targets before the timer hits zero it is a first person shooter but you can take the skills you learn here to create your dream game we will walk through the entire programming process and once the last Target is hit the player wins the game in this tutorial you will learn how to program with unreal's visual scripting language called blueprints design a user interface to display game information create custom weapons from scratch destroy objects using chaos physics and finally add our game to any environment you choose you don't need any unreal or programming experience to follow along everything throughout this process will be shown step by step it is important to know that I have another ue5 beginner tutorial that focuses on level and environment design so if you want to learn how to create your own environments then then you can check out that video this tutorial will mostly focus on programming now we are going to start with the very Basics if you already know how to navigate inside unreal and move objects then you can skip to the next chapter where we dive into programming with blueprints so with all that being said let's start creating our game we first have to download Unreal Engine 5. you can get on Roger 5 in the epic games launcher so select Unreal Engine and then select library now under here if you don't have any versions of Unreal Engine installed you want to click on the plus icon and then select the version you want to follow along with now in my case I already have the latest version of unrealgia 5 unreal 5.2 installed so I don't need to download it and if you are watching in the future feel free to follow along with a newer version of Unreal Engine like Unreal Engine 5.3 now I could launch unreal by pressing the launch button or within the drop down I can create a desktop shortcut so I can open up unreal without having to come through the epic games launcher so now that we have that shortcut I could just double click on it to launch Unreal Engine 5. when you open up unreal for the first time you will get the unreal project browser so the first tab that I selected is the reset projects which will of course have all of your recently edited projects now this is your first time opening up unreal this will be left blank now in our case I want to create a brand new project from a template so to create a product from a template go to games and now we get a bunch of starter games we can select from to start creating our game from now in my case I'm going to select the third person game even though we are later going to create a first person game I want to show off the features of unreal within the third person character project for now we will create a first person project in the next chapter and right here we get a bunch of project settings I'm going to leave them at default for now and for the project name let's call this my first project and then it's going to ask us a location that we want to save our project at so if you want to change this location select this file folder and navigate to the area on your computer where you want the project to be saved now in my case I decided to save it onto my desktop and click create now this is going to create a brand new folder on my desktop called my Project's name and if I open up this folder you will see all the folders and assets that make up my game now if I ever exit out my game instead of opening up my project through Unreal Engine I can open up the folder on my project and then double click on the dot U project to open it that way this is what you will see when you open up Unreal Engine in this chapter we're going to go over the basics like how to navigate it in our world and what all these different Windows do if you already know the basics then feel free to skip ahead to the next chapter where we cover blueprints for those who don't know or if you just want a refresher in the middle here we have the viewports so the viewport is where we're going to be doing the majority of our environment work now in order to navigate around in our viewport you want to hold down the right Mouse button so hold down the right Mouse button will allow us to pan my camera around while I move the mouse and with the right Mouse button held down I can use W to go forward s to go backwards a to go to the left and D to go to the right so that's right Mouse button held down wasd to move around and with the right Mouse button of course I can use e to go up or Q to go down so that's wasd q and E and if you're familiar with first person video games then luckily for you you already have the muscle memory to navigate in Unreal Engine now let's say if you don't like the speed of your camera maybe you think it's too fast or it's too slow you could change the speed of your camera by coming up here to this camera icon selecting it and then you can bring it down to make the camera slower or you could bring it up so we can make it something like 3.2 to make the camera faster and a shortcut to control the camera speed is to hold down the right Mouse button and scroll wheel so scroll wheel up to make the camera fast or scroll wheel down to make it slower now that we know how to navigate inside of our world it's time to go over how we can move 3D objects so first before we move it object we have to select one so to select an object hover over it and left click so that's left click to select any object in my world and with the object selected and the movement mode selected up here I get access to this little Gizmo if I hover over my mouse over any of the arrows I'm able to move it in that axis so hold on left Mouse button I can move this out like that and hold it down on the y-axis to move it in the y-axis now you notice by default that there's a little bit of snapping going on and that's because unreal automatically turns on Snap to grid to disable snap to grid I could come up here to this button and uncheck it to make sure it's no longer highlighted now our object will move smoothly we are not snapping a grid or if I want to say snap to something large like 100 I can select 100 right there and turn on snap it again and now my box will snap every 100 centimeters which is one meter I don't want to snap to the grid so I will just disable it now to rotate an object instead of selecting movement I select rotation so now I can rotate it on the different axes and you notice that it is snapping by default we can disable it just like with Movement by unchecking that button so now we get smooth rotation and if we ever want to undo an Unreal Engine you can always press Ctrl and Z to undo that and finally of course we have scaling so now I'm able to scale on the z-axis or scale on any of the axes individually you'll also notice that snapping is enabled for scaling so I can disable that right there so all the Snap Tools are up here in the top right now that I get smooth scaling if I want to scale in all three axes then I can hover over the white box in the middle to scale it uniformly or I could scale it just in two axes so let's say if I don't want to scale it on the x-axis I only want to scale it on the z and y then I can hover in between the two over the little line and then now I'm scaling on the two axes likewise if I go back to movement mode if I only want to move it in the Y and the x-axis then hover over the square in between the two arrows and then I'm only moving it in those two axes and finally a shortcut to move in between the different translation modes is to press W to get movement e to get rotation and R to scale so that is w e and r and if you don't like an object in your world you can always press the delete key or even press the backspace key to get rid of that object before we go over how to add objects to the environment let's go over the different view modes so you'll probably notice by now that there is a grid in my opinion I think this Grid in unreal is pretty annoying if you don't want to see your grid then you come up to show and uncheck grid right there to get rid of it also you'll see that we have all these little editor widgets that are around my world of course when my player actually plays the game they will not see these widgets these widgets are just here to help us the developer while making our game if we don't want to see these widgets and see exactly what the player will see in game then I can press the G key to go into game View mode so that is very important and this is probably one of the shortcuts you will use the most and that is g to toggle on and off game View mode so throughout this entire tutorial you'll see me select an icon and then immediately press G if I don't need it anymore so generally when I am working the only time I toggle off game View mode is what I'm trying to select an icon like the Sun make a change and then press G to hide it again and up here we have the different view modes right next to show here we will change what us the developers will see for example I can select wireframe to see all the polygon and edges that make up my world or I can select unlit to see what the world will look like without lighting which is helpful let's say we have a really dark environment and we can't see where our object is I could just switch to unlit and we have lighting only which as the name suggests will only show the lighting of the environments so this is what my world looks like without any materials but for now I'm just going to leave it on lit and finally let's say if you only want to see your viewport you don't want any of these other windows then you can press these buttons and down here select immersive mode or the shortcut is f11 right there and you can even toggle on and off game View mode right here so if I press immersive mode or f11 we get a full screen version of my viewport so I can only focus on my level and then when I'm done I can come up here and press that button again or I can press f11 on my keyboard to exit full screen mode now you're probably wondering how do I add objects into my viewport well you could come up here to the add button and hover over any of these objects for example I can drag in a sphere and then scale it up or I could come up to the add button and add in a brand new light like a rectangle light to go ahead and light up this corner and you'll notice that when I did drag it in we didn't see that widget and that's because I needed to toggle off game View mode with G in order to see it now that I know that I have my light selected I can rotate this to go ahead and illuminate that corner I would delete both of those because that was just an example if we want to add custom assets that are part of our project into the world then instead of coming up to the add button we will come down here to the content drawer which will show our content browser the content browser is important because it contains all the assets that make up my game any changes we make any programs or coding that we create will be stored here within the content browser and you navigate this similar to how you navigate your folder structure on your desktop so let's say I want to see the programming behind my character then I'll select third person and then I'll select the blueprints and here I get access to my character I can double click to open that up which will open up the blueprints on my character and we will go over this within the next chapter and if I want to get rid of this window I can click on x or I can drag this into my environment so let me go ahead and hover over the top here to bring down my content drawer and then I can drag out that object into my world press the backspace key to delete it because that was just an example now the shortcut to gain the content drawer that's how we don't have to come down here to the bottom left hand corner and select this button all the time is control and space so whenever I want something I can press Ctrl and space to open up the content drawer and if I want to search my entire content drawer for example let's get these boxes right here then I can select on content go to search and type in Cube and that will filter for all the different cubes and we have two cubes I want the blue cube so I can drag it into my world like this and here's a shortcut let's say if we want to know where a selected item is located within my content drawer because as you could guess if you are going to create a larger game you can have thousands of assets contained in hundreds of different folders and subfolders so it could be pretty confusing when you're for example just trying to find out where this ramp is located within the content drawer well the shortcut is Ctrl and B to jump to that location so by pressing Ctrl and B it automatically jumped to content level prototyping and the meshes folder so if you just select any object like the Box press Ctrl and B that will jump to its location within the content browser because our content browser is essential to our project you'll be opening it up a lot I would say the most common shortcuts with an Unreal Engine 5 are control space to get the content browser and a g key to hide and unhide our widgets okay so we're going to cover more of the content browser later but before we move on to programming let's go over our user interface and what exactly all these windows here do to the bottom right of my screen by default we have the details panel the details panel as you can guess we'll have all the details and properties of the object we currently have selected so if I selected this wall then we get the details of the wall or if I select this Cube we get its details and I can come into the details panel depending on what object we have selected and change some properties for example let's say if I don't like the height of my Cube then instead of scaling it with the r key I can instead go into scale right here and within the z-axis manually change it to 2. which will make it twice as large as beforehand and above the details panel by default we have the outliner the outliner contains a list of all the objects that make up my world so if I hover in between the two windows I can make the outliner bigger so that's how we can better see it and already you'll notice that every single object right here is within my world let's say if I want to grab SM underscore Cube 13 I can select that and now let's see okay I have this object right here selected and you'll notice that whenever I do select an object for example the blocks right here this selection will be reflected within the world or if I select an object within the viewports the object's name will be selected in the outliner and a details panel will change to that object also if I want to hide an object for example what if this cube is in my way then within the details panel I can hover over the eye icon to hide it and then I can select the eye icon again to unhide it now the shortcuts or hiding and unhiding objects is H so I can select this press h to hide it and then press Ctrl H to unhide it and here's a good tip let's say if our camera speed is really strong by holding down the right Mouse button and scrolling up and we just fly away and now we lost our world we have no idea where it is well I could come into the outliner select any of these meshes for example this Cube and press F to focus to it so that will snap me to the location of my object so I can select any location press F and I'll snap to it and you don't like the location of the windows of my user interface then I can hover over any of these tabs for example the details tab hold down the left Mouse button and now I can drag it around so for example I can drag the details panel over there or would I hold down left Mouse button on a tab to drag the window around I can drag it up here on top of another window now I'm able to switch in between the two tabs or I can drag it so hold down left Mouse button and just leave it in the middle of my screen to undock it from the unreal editor so maybe if I have multiple monitors then I could have some of my windows off to the side and if you ever want to close a window you can click on the X icon or you can hover over the tab and press the middle Mouse Button as a shortcut to remove windows and I know sometimes this tab right here can take up a lot of valuable space that we can use to show more properties so I can right click on that and go hi tab to hide that Tab and then I can hover over that little blue triangle select that to bring back my tab now let's say if I change my user interface to the point of no return I want to get back unreal's default user interface well I can come to windows down to load layout and select default editor layout this will restart Unreal Engine with the original Windows setup we had by default unreal doesn't show all the windows sometimes if we need to change something for example if we want to change the properties of my entire world then in order to get a window that's hidden I could come up to Windows and we get access to all my different Windows a common window we're going to use is the world settings so if I select the world settings it will immediately populate right here next to the details Tab and then I can switch in between details and World settings so that's how you create Windows and finally up here at the very top we have our toolbar and our toolbar is helpful because it has some buttons that we're commonly going to use for example we've already gone over the add tab which allows us to quickly Place unreal's default assets like lighting or basic shapes and we have this play button so as you can guess if you press the play button we are now playing our game so since we selected the third person template our game is just a third person character that can walk around and jump and then if I ever want to exit my game I can press the Escape key to go back into editing mode and another important feature of the toolbar is the selection mode up here so I can switch my different modes let's say if I have a landscape or want to create a landscape then I would select the landscape mode and this gives me all my landscaping tools now in this beginner tutorial we're not going to go over what these different modes are if you want to you can check out the other one if you are curious we are only going to go over blueprint programming not the environment aspects of unreal which are also really powerful before we go there is one last thing I want to mention and that is how to duplicate an object so let's say we have an object we made some changes in the details panel we like it and we want to duplicate it but we don't have to go through the process of pressing Ctrl MB to find where it is and then dragging in a new one and changing those properties instead what we can do is press Ctrl and D to duplicate so Ctrl D to duplicate an object and now we have two objects I can press Ctrl D again to duplicate it and right now it still looks like one object and that's because they're overlapping with each other so if I just move it use see that that was duplicated also a shortcut to duplicate an object is to hold down alt before you drag with the movement tool so hold down alt and then drag to drag out a new object so that's alt and drag which is a good shortcut and if we want to select multiple objects and move them as a group you could hold down shift to select multiple objects and then to deselect these objects you can hold down control and left click to deselect so now that I have these four objects selected I can move them rotate them and scale them as a group so press Ctrl Z to go back that is shift to select multiple control to unselect and holy down alt and dragging to duplicate now it is finally time to start talking about programming and when I mentioned programming probably the first thing that comes to mind is someone sitting at a desk and typing out hundreds of lines of code and while we can program games that way and Unreal Engine with the language C plus plus unreal also gives us the option to use their visual scripting language called blueprints so instead of writing hundreds of lines of hard to recode we can just get boxes and stream them together called notes logically they are the exact same thing as typing out code it's just another way to visualize your program and in my opinion it is a lot easier and faster than C plus plus so a common question is should I learn C plus plus or should I learn blueprints for most of your projects I would stick with blueprints especially if you are a beginner blueprints can do almost everything C plus can but even if you are going to use C plus plus you're going to encounter blueprints since blueprints are everywhere in Unreal Engine one way or another other you're going to have to learn Blueprints and then exactly what we're going to do right now we're going to jump straight into blueprints let's open up a blueprint and probably the most important blueprint right now for our game is the third person character so the default third person character that comes with the templates I'm going to press escape to exit game mode and then all of our blueprints are right now located within third person Blueprints and BP underscore third person character so if I double click on this this is all the logic that makes up my third person character and right now our window is hovering on top of our unreal editor I can hold down left Mouse button on the tab and then dock it up here that's how I can quickly switch in between my main map or any of the editor windows I have open before we dive into blueprints let's cover the user interface so right now we have the event graph in the middle here and the event graph is where we're going to be doing the majority of our blueprint logic and then to the left of that we have the construction script we will not be going over the construction script within this video because this is mostly used by artist and then to the left of that we have the viewport the viewport contains all the different objects that make up my Blueprints and it's important to note that in unreal objects that are inside of blueprints are called components so this camera right here is a component and this character is also a component and you notice that when I select on both of them their names are being selected within the components tab right here so this window is essentially just like our outliner for our world but it's for our blueprint so it contains all the components that make up this blueprint below that window we have the blueprint tab the my blueprint tab has all the nodes and variables that are contained in my blueprints for example in order to get to the event graph I could come up here and select the event graph window or under graphs I can select event graph to jump to that location we are going to cover more of the my blueprint window when we start to create notes and of course right here we have the details panel which allows us to edit any of the details of objects we have selected so if I have my static mesh right there selected then I can edit some of the details maybe I can even change out the mesh so right now it's the female mesh by default I can also get go here and then select skm underscore Manny to get the mail mesh and the controls of the blueprint viewport are the same as the level so I can hold on right Mouse button to go ahead and navigate or I can press the F key to jump to my selected components and I can use the scroll wheel to zoom out and zoom in and hold down alt and left Mouse button to rotate so alt and left Mouse button to rotate around an object and then use the scroll wheel to zoom in and out and here's another tip I can hold down the L key and the left Mouse button to then rotate my sun to see what my blueprint will look like in different lighting angles and finally up here we have our toolbar and the most important button up here is the play button so I can also play my game from the blueprint and it will open up a new window with my game so there are two ways I can play my game press escape to exit and all the way over here we have the compile button whenever we make a change to our blueprint like adding a new node within the event graph in order for that change to take effect I'm going to have to recompile my blueprint by pressing this button or I can just press play which will automatically compile all the blueprints that my game needs and finally because all these panels are widgets with tabs I can always grab them and then dock them to the side so I can customize my user interface and if I mess up my user interface I want the default user interface back then I can always go to Windows load layout and choose the default editor layout to get that back now it is time to create our first person shooter but in order to follow along with this tutorial you have to download some custom free assets designed for this tutorial you can download the assets Link in the description below now that we know how to navigate our blueprint editor I think it's time that we jump into a brand new project because of course you probably noticed that wait this is a third person character this isn't a first person shooter and that's the game we are going to be creating so let's go ahead and create a new project so specifically for the first person shooter and to do so I could come up to file and select new project up here to get the new project window or just like beforehand I can exit out of everything and then double click to open up on real engine two also get the unreal project browser now I could go into games and then start off our game for the first person template but to Future proof this video that's how in the future if they ever do change the first person template I recommend you start from the first person template project that is included within the downloadable assets so if you haven't already go ahead and download the target game assets Link in the description below once you have that downloaded you want to make sure before you open up the project you need to unzip it double click to open up and specifically we need to unzip the first person template so go ahead and drag that onto my desktop to unzip it okay now that it's unzipped let's go exit out of the unreal project browser we can rename this to anything I'm going to call this my first game and double click to open up its folder and I'm also going to rename it right here because the project is still called first person template so right click go to rename or shortcut is F2 and call this my first game also so now I can double click on it and that is how you rename projects in case you're wondering this is what you will see when you open up the first person templates this template is very similar to unreal's first person template except if I press play the gun is automatically spawned in which will just make it easier for us when I'm demonstrating the very basics of blueprints I could walk around with wasd jump with space and if I press left Mouse button I fire my weapon which are just firing bouncing balls and then I can fire that into one of these boxes which will fly away because they have physics and press escape to exit now let's go ahead and let's jump into our first person character to learn more about blueprints so press Ctrl and space go into first person Blueprints and right here is the character that we're using so if I double click on this this is the blueprints that make up my first person character and here is the viewport so as you can see it's just a capsule Collision a camera arms and a weapon and the weapon is built into the first person character let's go into the event graph now what exactly are all these notes and before we jump into what these notes are doing the controls are right Mouse button to pan so hold down the right Mouse button to pan My Graph and then use the scroll wheel to zoom in or zoom out so that's right Mouse button pan scroll wheel to zoom out or zoom in now we're going to start creating nodes stream them together change them to create our own game and don't worry I know this looks complicated we are going to create our own blueprint from scratch very soon I just want to have this open as an example to show what exactly blueprints are doing behind the scene so if we zoom in very simply these red nodes are events so these events could be linked to other blueprints or they could be linked to the player themselves pressing buttons on the keyboard for example this event is telling us that it's going to be activated whenever the player presses the left Mouse button so when they press the left Mouse button and executable wire will be shot out and then all the nodes that are connected to it will be executed in order first the player is going to press the left Mouse button then an animation is going to play we're going to spawn a projectile bullet which is the yellow sphere and then we're going to play a sound at location so all three of these nodes make up the fire logic or up here we have an action called jump which is leaked to my space bar so whenever I press the space bar the player is going to jump and then when I release the space bar the player is going to stop jumping and we can watch these nodes fire in real time now let me go move the details panel off to the side so we could see more of our Blueprints and then if I press play up here we get our little window now if I go into my game by clicking on the screen we no longer have access to that Mouse so if I ever want to get back my mouse I can press shift and F1 at the same time so that's shift F1 to get my mouse cursor so now that I have my mouse cursor and I'm no longer playing my game I can go ahead and make the window just a little bit smaller like that and then put it up here to the top right hand corner and I can watch my player characters nodes Run in real time by coming up to no debug object selected select the first person character to watch that blueprint's notes and let me make the windows smaller so I can see my game now if I walk around with my debug first person character selected we can see that right there if I press space those nodes are running in real time or if I fire my weapon you'll see the white line becomes orange which is telling us that all the nodes connected to the events are firing so when I press fire unreal will execute these three nodes in order and that's why blueprints are amazing it allows us to see the logic of our game running in real time so if there are any issues and we need to debug our game then we can watch our blueprint to see what's wrong and it helps us get a better sense of what is happening behind the scenes of unreal now let's go ahead and create an event and a node connected to it so to create an event or any nodes you just want to right click anywhere in the screen so right click an empty location and then we're going to create a new event which is linked to keyboard F so type in keyboard F and select it right there now whenever I press the F key this event will fire and anything connected to press will be executed now to connect the node to pressed I can drag from here and let go and unreal is smart enough to ask us what node we want to connect this event to and that is the print screen so go ahead and select grid stream right there now if we want to break a node connection hold down alt and left click so that's alt and left click to break a connection and you can always reconnect them up like this or you could hold down shift and click on the first pin and then click on the last pin with shift still held down to automatically connect them without dragging so that is alt to break shift to hook up two pins and let's say if you do hook up a pin and then you realize hey wait that's in the wrong location then you can hold down control and drag the left Mouse button out to go ahead and reconnect the PIN to somewhere else but in my case I want to leave that at pressed not on release and if you ever want to duplicate a node it's just like in our level hover over the nodes you want to duplicate and press Ctrl D and to delete them press the delete key again to add a node I can delete that node right there and right click and this gives me a list of all the nodes Unreal Engine has for us so specifically we want the registry node so I can type it in up here now this is very important let's say if you type in the name of a node and then it doesn't come up that's because unreal's context sensitive is turned on essentially what context sensitive is doing is that it's trying to guess exactly what node the player needs and I say for 95 of the time this context sensitivity does work but there's some rare cases where it doesn't work and you want a very specific node then go ahead and uncheck it to get access to more possible notes now in my case I'm generally just going to leave this on for now and type in print screen also this is me personally but instead of holding down shift to connect to pins I like to drag from here by holding down left Mouse button and connecting it up like that so the print screen will as you can guess print a screen onto our viewports so this will say something on the top left hand corner and we can have this say anything so I'm going to do the very classic hello world exclamation point and then we have a duration right now it's going to last for two seconds let's have this hello world last for five seconds so now if I move it right here and that's how I can see my window and press play let's make this a little bit bigger if I press the F button that will fire and in the top left hand corner we will get Hello World up there so that tells us that this is working and I could just Spam F and congratulations you just created your first event in Unreal Engine so what we're telling unreal is that Hey whenever the player presses f let's go ahead and print screen hello world but this logic is really boring now it's on to the fun stuff and that is actually programming our game to create a shooter game where the player has to shoot a bunch of targets within the given time frame but before we could do that we first have to migrate some assets so the assets we want to migrate are located within the downloadable content if you haven't already gone on that so go ahead and double click on it and we have the beginner game assets so go ahead and drag that onto your desktop to unzip it now this is going to contain a brand new project so double click to open up this second project and this will be the new project it's a completely Blick project except it contains some assets we want so it has the Sci-Fi weapons if I double click on it you can see what this is and it's a weapon that we're going to give the player and of course we have the target meshes now the reason why I didn't include this within the template is because it's a central note how we can move Assets in between two different projects so I want to bring these folders into my first game and to do that we first need to know the location of my first game so where is this project located luckily for us we saved it on the desktop right here called my first game so open it up go to content and then go ahead and copy the location of the content folder the reason why is because we're going to tell the other project with the assets where we want to duplicate these assets into so go ahead and hold down shift to select two different folders right click and then select migrates down here so it's going to ask us that we want to migrate all these assets click ok now we need to navigate to the location of the content folder of the project we're copying our assets into and since we already have that location I'm going to paste it right there and then select folder now I no longer need this beginner game asset project so I can go ahead and delete it right here okay now within our main project if I press controlled space we have our weapons and we have the targets now that I have my target mesh it is finally time to create our first blueprint class completely from scratch to create a blueprint and Unreal Engine let's first navigate to the folder we want to place it in and in my case we want to place it in first person blueprints so this folder right here and this is where I'm going to store all my blueprint programming logic now right click anywhere empty within the content browser and then select the blueprint class up here so it's the very first one which means it's the most important asset in unreal so let's select that and now it's going to ask us to select what type of blueprint we want to create and we specifically want to create an actor class the reason why is because actors are anything that can be placed in my world so let me exit out that so this box is an actor this son is an actor even our sky is an actor because we're able to place it in our world and since our Target will be inside of our world that means when we create the blooper class it has to be an actor so go ahead and select that it will ask us to create a name I'm going to call this BP underscore Target and BP stands for blueprints now you don't need to name this BP underscore Target you could just call this Target but I like to start all my blueprints off with BP just as naming convention but that's completely optional also if you ever want to rename an asset you can right click and select rename or the shortcut just like on Windows is F2 to quickly rename now let's double click to open up our first blueprint and immediately notice it is a blank except this little Widget theme in the middle here and that's just our scene's root so that's the origin point of our blueprints now in order to add our Target mesh to this blueprints we're going to go to Target right here and we have that static mesh so there are two ways to add it to the blueprint number one I can simply drag it on top of that default scene root and let go and then that will add it to my world or pressing Ctrl Z to undo that I can come up here and type in static mesh and select a static mesh component and then within the mesh component right here I can select the Target in the drop down so in the drop down type in Target and select it right there so those are two ways the shortcut is to just drag it onto the default same route which is easier now that we have our first blueprint we can start to add logic within the event graph right here which is completely empty except for the three events but for now let's compile and simply drag in that new blueprint that we created within the first person blueprint folder so if I drag in my targets now this is the blueprint we just created so all the logic we're going to add right here will affect this object in my world and because it's a blueprint I can hold down alt and duplicate it around my level and one thing I also notice that I have snapping turned on let me go turn it off snapping up there now here's a tip to open up Blueprints and that is let's say if I have my BP underscore targets window closed then I can always come up to my Blueprints and let's say I want to quickly edit it I could press Ctrl m b to find where it is within my content browser then double click to open it up that way or the shortcut is to press Ctrl and E to open up an assets editor so you can select any asset in your world for example this box press Ctrl D to start editing that assets let's add a little bit logic to the Target and that is specifically I want to create an event that will be activated whenever my projectile hits a Target so when it hits the targets I want the projectile to do something so first let's create the event by going back into our targets and then I want to select the static mesh Now by selecting the static mesh if I scroll down we get all these events we can create I specifically want the on component hits so whenever something hits this target this event will be fired so click on the plus icon to create it we don't need these events right now so let me delete them we will go over what they do later and I'm going to hook up a new note to this so just double check that this is working and that is a print screen so I use print screens everywhere to debug and make sure that I'm going on the right track when programming my game and the stream will be let's call this target hit exclamation point and some nodes will have advanced options if I select this arrow and protect color let's make this reddish so that's why I can actually see it because our sky is blue it's kind of hard to see blue text in the top left hand corner and for duration make it five seconds a little bit longer so press play and now if I fire my weapon boom we'll see that the target is hitting this event is working but we have a glitch right now and that is my player can come up to it hit the target and then they will start saying that the target is hit so this is exactly what I don't want to happen I only want that event to run when we fire on it so in order to do that move the events and drag from other actor and then type in cast to and then the name of our bullet so our bullet blueprint right now is called BP underscore first person projectile so if I open this up this is the blueprint that's been spawned whenever my character fires so right here I could drag from other actor and go cast to first person projectile which is the name of my sphere bullet and hook it up like this so casting is a whole nother lesson but essentially what it's doing right now is that's asking hey is this actor that's currently hitting my static mesh is it a first person projectile and if it is a first person projectile then we can execute everything that's connected to this pin if it's not then this pin will run and we can see if this logic is correctly running in real time buy first let me go ahead and let's delete those two Targets so we only have one target to make it a little bit simpler and also let me scale it up so it's bigger go back into my Target Blueprint and press play so now if I press fire then Target his hit but then if I walk up to it you'll see that the execution gets to the cast so it gets the blue node and then it stops because hey this isn't a projectile that's hitting the static mesh it's the player character so it's not gonna run only when I fire on it will it run now we need a way to track how many targets are hit so if I come into here and if we have multiple targets I want to be able to know how many targets have been hit so for example it would be two right there and then if there's only two Targets in my world then that means the player has won the game in order to do that we will use a game mode and the game mode is what you expect it's a blueprint but it handles a lot of the game features so if you're playing Capture the Flag then the game mode will keep track of how many flags each team has captured but in our case the game mode we keep track of how many targets the players hit and the timer of the game press control space to go back into reverse person Blueprints and the template already comes with a game mode I want to create one from scratch to go ahead and show how you create one so let's right click go to blooper class and select game mode base and I'm going to call this one GM underscore for game mode and let's call it Target game so this will keep track of all the logic of my game it will tell us where not the player one or whether or not the player lost and if I select last defaults we already get a bunch of details that we can set right here so I can select what the default Pawn class is this will essentially tell us what blueprint should the player control and right now it's set to default Pawn which is not what we want I want to set this to BP underscore first person character like that now in order to tell unreal hey I want to use this game mode we need to go back to first person map and then go into the world settings Now by default we don't have the world settings so to get it to go to Windows down here to World settings select that and Within game mode override go ahead and select the new game mode we created GM underscore Target game like that so now we're using GM underscore Target game also right now our character doesn't have a Crosshair I want there to be something in the middle screen to tell our player where they're aiming at so let's go to HUD and then select first person HUD which was included in the assets you migrated over it is this first person HUD that we're using now if I press play we get a little Crosshair in the middle of my screen so as you can guess the game mode is essential to any game you create and this game mode will have to keep track of how many targets the player has hit and in order to do that we need variables so if you've ever coded before you know exactly what I'm talking about but essentially variables contain data so whenever we have something we want to store we store that within a variable and to create a variable we want to come all the way over here and select the plus icon now this is going to go ahead and create a new variable down here and let's call this my VAR for my variable and then it's going to ask us what type of variable do we want for demonstration let's select an integer which is a whole number now you'll notice that within the details panel we're unable to change that value that's because I have to First Press compile and now we get access to my VAR so this could be any number this could be 0 10 or even negative 10. we can leave it at 20 for now and then in order to get this variable I can drag it out into my graph let go and it's going to ask us if you want to get it or set it I'm going to select get for now also it created two custom events by default we are going to recreate them but let me delete them for now so now that we have our variable inside of a graph that's set to 20. whenever I drag this out it's going to get the value that's currently storing which in my case is 20. now I'm going to go bring back that event that we deleted called begin play now a begin play is very simple this will fire once at the beginning of every game so as soon as I play my game this event began play will fire and we could see this in action right now by dragging from here and typing in print screen once again let's go ahead and let's see what this variable is currently holding by reading it out to the print Street holding it over the input and letting it go like that so this will convert my integer into a stream which is what the print screen is asking and let's make this text color red so I can actually see it and press compile now then the first person map because within World settings we have that game mode selected that event begin play should fire so if I press play the top left hand corner we get 20. so that tells us that everything is working and this variable is storing our values that's how you create a value when you're starting off what if you want to change this value during gameplay well I can drag my bar back into the graph then instead of selecting get we select set so this is how we override whatever value is currently within your variable so for example let's go event beginplay and then instead of 20 which is what it is by default it will be let's go negative five right so then we plug that up to print stream that means when I play my game our value is first going to start off as 20 then immediately it's going to set it to negative 5 and then that should print out negative 5 instead of 20. and up here we get negative 5 instead of 20. so that's how we change the variables of our game so now that we know how to handle variables let's create a new variable that will keep track of how many targets the player has hit so let's go ahead and hover over all those and click delete now I'm going to delete that variable and click the plus icon again and call this current score I could have renamed the previous variable because we want an integer but in case if the variable that you created is not an integer make sure you select it right here now I'm going to drag this into my world and we're going to get it so we're just going to get this current score and then drag from here and type in plus plus so this would be increment integer what this node will do is that it's just going to add 1 to this variable people and then is going to set it so if this variable was 3 and then this ran then the variable would be four but we need a way for our Target blueprints so our Target right here to be able to tell the game mode hey I want you to execute this node and we could do that with a custom event so I can right click anywhere in my graph and type in custom events and click enter to get it now we can name this event anything because it's custom and we will call this add score and then plug it up right here so now whenever this event is called then we're going to add one to the current score and in order to see the current score of course we're going to use a print screen so when you are creating a game from scratch in Unreal Engine you will be using a lot of print screens and I can drag from here or I can even drag from here but I'll just drag from the output right there and let's make a duration of five with a text color of once again orange so it's easier for us the developers to see and press compile now of course if I just go into my game and I start firing all my targets nothing's gonna happen and that's because I need to tell unreal when we want to call this event so we want to call it through the targets that's why we created this on component hit event because now I want to get the game mode and add one to the score so let's go ahead right click anywhere and type in get game mode which will get our world game mode and then if I drag from here and type in the name of the custom events which was add score nothing is going to come up that's because I need to tell unreal hey when you get the game mode I want you to treat it as GM underscore Target game so what do you tell unreal exactly what game mode are we getting and that is cast to GM underscore Target game which is the game mode we just created and we will hook it up here like that and also I can delete this bridge trains because we no longer need it now I can drag from GM Target game and then type in add score and click enter so now we are calling the custom event that we just created and I could double click on this ad score which will take me to that event now this should work so let me go move this off to the side Press Play If I have my first Target selected so let's go ahead and select GM underscore Target game now if I fire on it you'll see that we get one two three four five six seven eight and I keep on firing and that increment will increase so that's how we know our ad score custom events is being called from our targets now we do have a really bad exploit players could use and that is what I want to happen is that the player hits one target so 1.2 and 3 and since it's three out of three that means the player wins but right now the player can get to a count of three by coming up to just one Target and going one two and three so I want it where whenever I hit an object after I hit it again this event right here no longer runs and we're going to do that with a new variable and that is a Boolean so let's come to variables and add a brand new one within our targets and by default it is a Boolean we can always change that by clicking on this button and selecting Boolean and let's rename this variable up here to is hit question mark since this variable is a Boolean it stores a true and a false value this variable will tell us whether or not this target has already been hit if it was hit this is true if it hasn't been hit yet then it will be false so I could drag this into my graph and we will get it now we're going to go over one of the most essential notes or probably the most essential node of Unreal Engine or just programming in general and that is the if statement so right click on the graph and type in if and in Unreal Engine they call it a branch so select a branch but the branch is an if statement or hold down B and left click to create a branch and that's how Central this node is the fact that we have a shortcut so be it left click to create it means it's pretty important so I could delete those because we don't need it and now let me go ahead and let's move all these nodes over there and first we're going to see whether or not this object was hit so if this object was hit which means if this value is true then we don't want anything to be plugged up here because the object was already hit we don't need to make another call to the ad score I only want to make a call to the ad score if the object hasn't been hit yet so if it is false but I can't just plug it up like this because we have to set the is hit so let me drag from this variable and select set now let me go and let's move these nodes right there and then hook up the is set to false and then hook it back up to the casting node when a projectile hits our static mesh we're gonna check has this already been hit if it has a bit hit if it's still false then we're going to set it to true so that means our object has been hit and then we make a call to the ad score so the next time it is hit because is hit is now set to true then the true statement will be Rand and not the false statement and since nothing is plugged up that means nothing is going to happen now if I play my game walk up to a Target hit it once it adds to the score and then if I hit again it doesn't add anything I have to hit the other targets to add a score so now we're at a score of two and three and now we won the game I can't just keep spamming these different targets to increase the score so let's jump back into BP underscore targets now generally and this is just Aesthetics you do not have to do this we want to hook up the bulk of my nodes to the true pin and not the false pin the reason why is because it just looks nicer so it organizes our graph just a little bit better and we could do that by checking if this is hit is a not Boolean so type in not Boolean and then plug it in so now we're checking if is hit is not set to true so if it is not set to true then we will hook it up through here and set it to true just like that so all we did was added a knots to go ahead and flip the executable and here's a tip instead of dragging a variable into my graph and then selecting get or sets I can hold down control and drag it in to automatically get it or hold down alt and drag it in to automatically set it so that is another nice shortcut to prevent one more click before we move on to the next chapter let's briefly go over what we did this event will run whenever our Target is hit then we're going to check if it was the first person projectile that hit it and if it was we will then check whether or not this target has already been hit and then if it hasn't already been hit then we're going to set that variable to is hit to true so that these nodes will be ran again in the future and then we tell the game mode to add a score to our current score and if we jump into the first person map here's what we have we could add one two and three so our game is slowly forming but there is one gallerian issue and that is it looks kind of ugly have a new rely on the print screen note to keep track of all of our scores looks really bad this is where user interfaces come in handy in unreal you could create a user interface using unreal's motion graphic UI designer which is a mouthful so it is called umg for short right now we will create a user interface to keep track of the player's score which is how many targets are left for the player to hit and we can create the user interface by making a widget blueprint before we create our user interface don't forget to save everything because I'll be very unfortunate if we lost all our progress so select save all and go to save selected Now to create a user interface we need to create a widget so right click and go all the way down here to user interfaces and select widget blueprints now it's going to ask us what type of widget blueprint do we want to create we just want to create the basic one and call this wbp for widget blueprint underscore UI because this is our main user interface that will be displayed whenever the player is playing the game so let's double click to go inside of it and here in the middle is where we're going to create the user interface on the top left hand corner we have the palette the palette contains all the items we could display to the player and before I drag in anything the very first item you need to drag in is the canvas panel so whenever you create a new widgets the first thing you need to do is add in a canvas panel and let go so let's go ahead and let's move the details panel off to the side so we can better see it and the controls are the exact same as the blueprints hold down the right Mouse button to pad and use the scroll wheel to zoom out and zoom in now we will add in text so I could come to comment and drag out text or I could type in text right here and drag it out like this so now we have text that will be displayed within the game and you'll also notice that we have this little flower icon right here and this flower icon is anchoring so let me go show what this is so let me go place this at the very top left hand corner or I could come up to Anchors within the details panel and select the top left hand corner now in order to change the text within details go to text and we could call this something let's call this top left now all the items we add to this widget will be down here within the hierarchy so you see we already have text top left if I control C control V we now have another top left that I'm going to drag all the way to the right over here and within anchors select the right hand corner now we're going to call this one top rights and then Ctrl C Ctrl V again drag this into the center and for the anchor select Center and this one will be called center now I'm doing this that's how we know exactly what these anchors are doing now let's press compile and I want to display this widget blueprint as soon as the game starts so we could do that within the game mode and we go plug it up to event beginplay as a reminder in case you don't have it just right click anywhere and type in event beginplay so as soon as our game starts we will create a widget and that widget will be the one we just made which is wbp underscore UI okay so let's compile and if we play our game uh oh we do not see our widgets and that's because within the game mode I'm creating the widget but I'm not displaying it so drag from the return value which contains our widget and now we're going to tell unreal to add that widget to the viewport so we'll create it add to viewports and now if I press play our event begin play will fire and create our widgets and we have our widgets so we have top left top right Etc and notice how when I change the size of my window the center is saying in the center and the left-handed right hand Corners are staying within their corners and that's exactly what anchors do it's essentially like responsive design it ensures that this piece of the user interface will always stay there in relation to the player's window because not every window will be 1080 by 1920 some windows can be really long or maybe even someone's gaming on a one by one monitor people's setups can be pretty weird so I do not need the center and I did not need the top right because now just an example I want the top left right there and we will call this score so this will contain the score of my game but if I press play honestly this widget is a little bit too small right now I want to make it bigger so let's select score and within appearance we have size so let's make this a size of let's go 64. because that was too big we don't want it to take up the entire screen actually let's try 45 okay that looks good I will actually just increase that a little bit more to 50. and now that we have a score in the top left hand corner I want that score to update whenever I hit a Target and to do that we can add some blueprint logic within my user interface to tell the user interface exactly what score should be displayed and we could do that within the graph so not only do our widgets allow us to create a user interface they also allow us to create logic right here and I'll go select all that and delete it now I specifically want to update this text right here and I first have to name this text so let's call this score text the reason why is because I want a clear name so when I'm in the graph I'm able to grab score text and update it but you notice that wait there's nothing within my blueprints I can't update that yet and that's because you also want to make sure that is variable is turned on so select it and turn on this variable now we get access to score text right here so I can drag from here and get the score text and then in order to update the score text drag from here and go set text text and select that so now this is going to change that text to whatever is inputted right here and to show that it is working let's change this to hello world and then hook it up to an event begin play but widgets don't have an event begin play instead they have an event construct which will run as soon as the widget is created so it's essentially like an event beginplay so if I press play now hello world is being displayed instead of score now I want this to display the current number Counts from our game mode so get current score and we can do that by first the leading event construct because that was just an example and create a brand new custom events call this one updates score and then hook it up right there but actually before we do we need to first get the game mode and then do exactly what we did within the targets and that is cast to GM underscore Target game so cast to GM underscore Target game to get access to current score all the variables and custom events that are located within our custom game mode and then I get dragged from here so let's drag them here and go get current score and select that now I will drag from it hover over hello world and let go to convert that integer into a string and hook this all up like that says compile save and now of course if I play my game and if I fire that score will not be updated that's because we need to call update score within the game mode so as soon as we add a score then we're going to update this widget up here but in order to call the update score custom events we first have to get a reference to it so we're going to take this event and store it inside of a variable so to do that I can come to variables create a brand new one and call this one user interface now as for the tie instead of selecting one of these types I will type in the name of my widget which is wbp underscore UI and then just select an object reference now I can hold down alt to set it and then I'm going to plug up the return value right there and plug it up like this so that's how as soon as I create my widget we will store that widget so now that I have access to my widget I can come down here so let's drag this user interface by holding down control so I can get it and then we will call that custom event that we made called update score and select that and luckily for us we no longer need that ugly print screen so we could kill it and then plug up update score like that now I know that was a lot to just create a variable to store my user interface instead what I can do it let's delete user interface real quickly and also delete the variable hold on alt to break that here's a shortcut instead of having to come down to variables and manually create it I can right click on this output and go promote to variables that will automatically create a variable that stores wbp underscore UI and then we can call this one user interface just like that and hook it up like this and then hold down Ctrl drag and hook it back up to update score so that's the shortcuts to quickly created variables you can pretty much come to any of these outputs for example this integer right click and promote to a variable to quickly create one without clicking on the add button now if I press play we will update that score so it goes to one two and three which is what I want but I also want it where before we display the number we have the word score so it's score space and then it displays a number so let's go back into our widget blueprint and we're going to do that by dragging from in text and type in append now this is one of those cases where it's not showing up so we have to uncheck on text sensitive and we will append the string down there so select that and now that's going to automatically create two different nodes so the purple node is streamed and then this string is being converted into text essentially strings and text are the exact same thing they store words and then I can delete this two text right there and let's go move everything over here and this append will add two sentences together so for sentence a let's call this score space and then B will be current score so we're going to add current score to the sentence of score space which will then be displayed in the text okay so let's compile save again and now if I press play we have score one two and three So within the user interface let's go back to designer select score and then for the text let's make this score space zero now we start off with a score of zero and then in increments as we hit different targets one last thing I want to do with our user interface if we go into graph and that is this is pretty messy we have to get the game mode and then we have to cast to it get the current score what I can do is simplify this so I can delete good game mode and the cast and the current score and then within my custom events in the details panel we have this inputs so I can pass variables through events so let me click on the plus icon so that's what we better understand what I'm talking about and this input will be called current score and we're going to ask for an integer so now we can plug that up and it is this current score that will be plugged up right there so if I press compile and go back to GM underscore Target game you'll see that when we call that custom events we're able to pass data through it in our case current score to the custom events where then that variable can be used so this current score will of course just be the current score outputs right there so if I press play now it increases without having to make a call to the game mode now before we go over adding a win condition to our game mode I want to briefly mention how we organize graphs now let's say for some reason our current score is random as soon as we create our widget well I can't within the widget just manually set the score to zero instead I'm going to have to call the update score right here so I will drag from the user interface and then type in update score and then hook it up but you notice that now it is pretty messy because we have a line that's going through a node holy could leave it as is there is nothing wrong with that and our game will be completely fine but for a sanding check for us the developers this is messy so what I can do is hover over any lines and then double click to add a reroute node so this will allow me to just move my line for organizational sake just like this so now my graph looks a lot nicer and in my opinion it's a lot more readable reroute nodes are amazing you get pretty much organize your graph whatever way you may like so let's press Ctrl Z to undo those and another thing we could do is hover over a set of nodes and press the c key to comment so this is going to add in a comment and I can say add score by calling the widgets which is useful for us or other members of our team to remind us exactly what a set of nodes are doing so I can delete that comment and we can even comment individual notes so if I hover over any of these nodes we'll get this little comment icon right there I can select it and then I can say hello world so I can add comments to any of these nodes which is helpful if we're doing something confusing and then I can press that button again to get rid of that comments and in my case I'll just leave updates for right there because we do want to start off the event begin play with a current score of zero always don't forget to save everything we've done so we don't lose our progress and now let's go see our game and we have three targets so I hit one two and three and at this point I want to be able to tell the player that hey you won the game because you hit all the targets so in order to do that we need to go into GM underscore Target game and we have to create a brand new variable that will be our Max score so our current score is how many targets we hit so far and our Max score is how many targets we need to hit to beat the game so let's go to variables click on a new one and call this one Max score and then for variable type this will of course be an integer because it's just a whole number now we need to give ourselves the ability to somehow count how many targets are in my world right now there's three and we can do that by first let's break these notes and select them all then move them off to the side and then drag from event beginplay and we're going to get all actors of class and specifically we're going to get all actors of class for a Target so BP underscore targets so now we get a reference to all the targets and you'll see we have this really weird Al pin which is a bunch of squares this is an array don't worry we are not going over a raise in this video but what matters is that this stores all the different targets and because it stores all the Targets in my world that means I can see how many targets there are by dragging from here and typing in length so it is this outputs that gives me the amount of targets we need to hit so let me move all that over and then hold down alt drag Max score to set it and we will set that length to the max score so what these three nodes are doing is that it's going through my entire world counting up all my targets and then it is setting it to the max score variable right there and now let's jump back into update score by double clicking on it we need a new input variable so click the add button and this one will be Max score of course of integer and then we will add another pin and let's make this a slash so we're gonna current score slash the max score so the player knows how many more targets they have to hit so drag from there and add it like that Fresco pile and now back in our Target game we need to fill up the max score with the max score integer so hold down control and I could drag it into my graph and then plug it up or shortcuts holding down control I can hover over Max score and let go to automatically connect that up so same thing right here because right now the max score is set to zero now if I play my game we have a score of 0 out of zero which doesn't make any sense so for Max score drag that right there so press play we have a score of zero out of three one out of three two and three out of three and then at this point I want to tell the player congratulations you won so let's go add in that win condition whenever the current score is equal to the max score so after we update the score we will add a Boolean value so hold down B and left click to breed in a branch node or you could right click and type in if so let's go plug this up right there and grab the current score and grab the max score so we have a bunch of comparison notes now we could check if one is greater than the other but in our case we're going to check if one is equal to so equal equal the other so when current score is equal to Max score that means if this is true congratulations the player has won and in just a minute we're going to create a proper widget but to make sure that this is working you guessed it we will use a print screen so let's go congrats you won Miley face okay compile and actually we won't be able to see this so make sure this is red with a duration of five seconds also here's a shortcut you could press alt and P to automatically play my game instead of selecting the play button so that is another shortcut is alt and P to play the game we hit one two three top left hand corner we get the print string congrats you one now it's time to create a widget that will stop everything in the game stop what I'm doing and tell the player you won because right now as is with the little prince to read they probably won't recognize that hey the game is over stop playing we will use the exact same process to create the windscreen as we did when creating the user interface right here so press Ctrl space and let's create a brand new user interface widget blueprints and that is wbp underscore end screen because this will handle both the windscreen and the lost screen so let's double click to go inside of it first thing you need to do with all widgets is add in a canvas panel now in Unreal Engine 4 this was added by default I don't know why we have to manually add it now and then we're going to go to text and drag this in let's put this into the middle of the screen make this fairly large so let's go 60. and let's even make this bigger and I want to justify it in the middle of the screen so go ahead and do justification and select the middle one now right now our text is looking just a little bit Bland so we can add some spice to it with a drop shadow so first in order to enable drop Shadows I need to go within the shadow color right here so select this and then increase its Alpha transparency right now it's zero which means there's no Shadow to 1 which means our shadow is full black and then for shadow offsets change this that's how we can slowly bring this out to make just a little better offset okay there we go and then for the text this will be U1 exclamation points smiley face with a nose boom okay we're gonna leave this as is for now but we are going to edit it in just a second but I want to First display this in my world when we win the game so of course we're going to do that within our Target game which we will be replacing this print screen so let's go ahead and delete that actually let me go move my note set down and then drag from True creates a widget and that widget is the end screen that we just made and then add it to viewports so the player can actually see it okay press compile now if we go back to our game score is zero out of three let's go increase that and then we won but there is an issue that is the player can still run around and now this U1 screen is just stuck to my player and we have no option to replay my game so let's go ahead and add that option right now so you have the option to restart we need a button so go back into the end screen and type in a button to go ahead and get it so let's drag in our little button and for the anchor of course we're going to set this to the center let me go adjust my button like this to make it bigger and then add text to my button so drag out text and hover over and then let go so this text will ask us if we want to restart so restart question mark also my button is way too bright so go to style and under normal for tint decreases to something more darkish like right there okay that's better press compile and now if we play our game we have this U1 but we're still playing the game and plus we don't get access to our mouse cursor so we want to stop playing the game and we want to give the player the ability to get back their mouse cursor now for us the editor we can just press shift and one to get our Mouse but the actual player won't have that ability but before we do that I want it where when I press restart then the entire world restarts so let me go to wbp underscore end screen select my button and then with my button selected all the way down here create an event for on clicked you will notice that this is event on clicked or a button called button underscore zero so that name doesn't really make sense we can rename it right here to restart button okay so what I want to happen is that it reloads my current level right now my current level is called first person map so let's drag from here and go open level by object reference and that will be this level which is first person map okay great now let's stop the game and show the player's Mouse so jump back to GM underscore Target game and then as soon as we win our game we add the windscreen we will drag from here and go set input mode UI only so that means the player can only input actions to the user interface and the specific user interface I want the player to interact with is the end screen so drag from here and let go like that also double-click to add in a reroute node and now it's asking for the player controller so drag from here and go get player controller you can think of the player controller as a reference to the player itself and then to show the mouse cursor because the mouse cursor will not show up drag from here and go show mouse cursor and we're gonna set it so we're gonna set whether or not we see the mouse cursor and set that to true so we do see it again okay compile press play Moment of Truth one two and three we won and immediately we get back by mouse cursor I didn't have to press shift one and then if I select restart we restart the game but there's a glitch and that is I can't move around anymore I need to reset the input mode to game only so let's come up here and then at the very beginning of my game that our info mode will be set to game by getting the player controller again so let's grab that and then drag from here and go set input mode game only okay so now we are getting the game and go ahead and re-plug it up right there now we do have one issue still and that is if we beat the game with the player walking around so let's say the player is walking towards the target then hits it even though we have no access we're unable to move our player around our player is still moving forward so we need a completely disable movements because that is a glitch so go into let's go back to Target game and down here drag from the player controller again and let's get a set ignore move input so this will stop all the movement of my player character okay now we want a new move input so any movement that we were doing will be halted and stop immediately once the end screen is shown now if I beat my game when I'm running so let's go fire right there and okay my player does stop and then I can click restart and get back my player and let's make the end screen a little bit nicer because right now it's kind of bland so to do that let me go to end screen and go back to designer and right here I'm going to add a blur so type in blur and drag in the background blur now I want this to take up the entirety of my canvas so go ahead and make that really large so the cup is this by entire canvas and for the anchor make sure it's set to full screen so that the blur will be everywhere no matter the size of my game window and then with blur selected let's increase this to two and then you'll notice uh oh we are blurring the entire screen that's something we don't want to happen and the reason why is because background blur is at the top now unreal is different from other programs like Photoshop where the last item is actually at the top and then the top item is on the bottom so I have to drag this that's all right after the canvas panel I let go it will blur it so now our text and the restart button are above the blur background all right now before we add a timer to our game Let's really briefly go over exactly what we did so far since is this your first time creating a game we have done a lot so to begin we created the Target Blueprint and the Target Blueprint is really simple it's just a static mesh and we check whether or not a projectile is hitting that mesh and if it is we're going to add a score to the game mode and then make sure this target can't be hit again in the future with these two nodes and then into game mode is where the majority of my game is and so far our game has been pretty simple as soon as the player starts playing my game with the event begin play unreal will try to find how many targets are in my world and set it as the max score so for example right now we have three targets if I create a fourth one then we're gonna have a Max score out of four instead of three and then we create our user interface now whenever the target is hit we will add one to the current score and then we'll update the user interface and check if the player has been in the game by seeing if current score is equal to the max score and then if it is we add the windscreen to tell the player that they won and then we stop our players movement so this is what we have so far I can fire one two three and then four and we won right now the game is fun but it is not challenging the player has infinite time to hit all the targets so let's make it challenging by adding a timer so the player will have to hit all the targets before the timer expires and if they don't they lose the game that means we can either win the game or we can lose it before we create the timer let's make the game a little bit harder by spreading out my targets so let me put a Target all the way over here put this down let's grab all of these and bring them all over here maybe one's bigger than the other and if I want to rotate the targets I can press e but then you'll notice I'm unable to rotate the Target in the target's Direction so when I try rotate it it does a weird rotation if I want to rotate the Target in its direction then come up here and select the sphere icon to make it a cube now I can properly rotate it the way I want and just like in the blueprints we're in the viewport I can hold down L and left Mouse button to rotate my sun in my world I can hold down control and L to rotate my level Sun so that's control and L hell down to rotate the sun let's go angle it right there but now if I play my game our player will spawn all the way over there then I have to walk over here to shoot my targets and that's because we have our player start right there so wherever my player start is is where the player will be spawned so if I move this in the corner press play and the player will be spawned in the corner and if your world doesn't have a player start then we press play we will start from our editor cameras location so if I press play we just start at that location that we were at now to get a player start it's very simple come up to that button go to Basics and then drag out the player start so that's how we bring one into our level and let's angle it so it's facing the targets and then press play so respond looking at the targets just in case if you ever do want to play your game not from the player's start but from the camera then if I click on these three dots down here under spawn play rats we can select camera location to spawn once again at our camera's location instead of the player start and to switch that back select player start now it is finally time to add a counter to my game so that the player has to quickly hit all the targets if the timer expires and it hits zero then our player has lost so of course we're going to add this game logic to our game mode now we have our ad score event and all the nodes connected to it let me highlight everything and move it down just a little bit because we are going to be adding to the event begin play So at the very end of the event begin play after recreate our user interface let's add in some new functionality by dragging out here letting go and creating a brand new node called set timer by events so what this node will do is that any event that is hooked up to this node will run after a certain time so if I drag from event I can create a new custom event and call this decrease counts I need to tell this node how many seconds until this event can run and for now let me leave it at one second and to show what this is doing let's drag from here and go print screen and this is decrease count is activated okay so now if I press play you see that this runs and then after one second our decrease count will be activated and then a print stream will be run but it just stops we want this to run every single second and not just run once and that's where looping comes in handy so if I turn on looping and now if I press play after one second it runs two seconds three and so on so every single second this event is being activated which is what I want because we're going to set this to 0.1 seconds and now you see that every 0.1 seconds it runs so we're going in a lot of decreased counts being activated let's create a variable that will hold our time so click on the add button and this one will be called time press compile so we're able to change our default value and set this to something like 500. now I want it where whenever this custom event will run one will be subtracted from time so I can hold down control and drag it out to get time and delete the print screen since we no longer need that and let me go ahead and move all these nodes down to give myself more room and we're going to do a similar thing that we did right here where instead of incrementing current score we will be decreasing Time by giving it a minus minus so minus minus to decrement that integer and set it and in order to see what our time is we will add in a print screen as you can guess we will add this to our user interface in just a second so plug that up and within the advanced menu let's make this red so I can actually see it and it's going to decrement every 0.1 seconds that's too slow so it will decrement every 0.01 seconds and now if I press play we'll see that it goes down from 500 it continues decreasing up until we get to zero announced at the negative range so it's going to keep going down down all right now that I know my timer is working let's add it to the user interface and we will do the exact same thing we did with update score so double click to jump back to our user interface widgets within the graph and create a new custom events that will be update time and go into designer because we need to create that time text so what I could do is drag in text like that or to keep it consistent so it has the same font I can select the other text Ctrl C control V it and place it all the way over here so instead of having a b score it will be time and it will be anchored to the top right hand corner so anchor top right hand corner we will give this a name so we're able to tell what it is within the graph and that is time text go to graph and let's get the time text drag up here and go set text text just like that and we're going to give it an integer input just like with the update score so click on the plus button change this to an integer and this one will be new time all right let me hook this up like that and then drag from in text and we will use the two text string select that and then once again use the append node that we're using up here so that's how we get append our time to a sentence so pin that to B and the sentence will be time space now we need to call this event within the game mode so let's go back to decrease counts and it gets the user interface which we're setting right here so we're getting that user interface we created and we are updating the time so the new time will be the time after it's decremented and we also have to update the time before the set timer events so go ahead and copy these two nodes and then set it right here like that and since we are getting the variable that we set right here I could delete the user interface and then drag from here to keep it consistent because it's the same thing and this will be set to the default time which is right now set to 500 so go ahead and drag it onto new time like that so if I press play we have a timer going down from 500 all the way down to zero and then it goes into the negative range which is something we don't want also keep in mind that you can adjust the difficulty of your game by increasing or decreasing the time so if we want a really fast game instead of 500 it will be 100 so now there's 100 units and then immediately goes to zero so let's leave this at 400 and add in a lost condition so the player will lose when this time is less than or equal to zero so drag from time and go less than and equal so now we are checking if this variable is less than or equal to the number right here which is zero that is what I want hold down B and left click to edit that if statement which is asking for that Boolean so now if this is true that that means the player has lost which is pretty bad so we will drag from here and go print screen all caps you lost again we will add this functionality to the end screen in just a moment but let's see if this is working so start from 400 goes down and then it will hit zero and now it says you lost you lost but we continually lose and the timer is still running I wanted to stop at zero so I will add in a new variable and this variable will check is game over question mark and because it's a question mark it will be a Boolean so if it's true the game is over if it's false then the game is still running and since the player did lose the game hold down alt and drag it into my graph to set the game over to true we no longer want to run this game and then added another Boolean statement so move this all over here and if you ever want to select multiple nodes just like in the viewport in case you don't know you can hold down shift and left click if you don't want to drag out a box so hold down B left click to add in a branch and now we will check so hold down control and drag out his game over whether or not game over is set to false so we want to make sure that the game is not over yet with it not Boolean and then we decrement our timer so let's see if this works it goes down to zero soon and there we go it stops it will only get one you lost okay now we're going to replace the print screen with the actual end screen and luckily for us we already have the logic to bring up our end screen all the way over here so I can highlight all these nodes that make up that logic which is creating the end screen and stopping our players movements Ctrl C and control of Viet over here now do not worry we are going to go over how we can simplify this so we don't have to duplicate nodes in a moment but let's highlight everything and plug it up right there now we have one big issue and that is if I press play and if the timer goes to zero we get a U1 screen we want to display that the player lost so we will go into our end screen go into the graph and then I want to add a brand new Boolean value so let's go ahead and let's create a new variable and this one will be lost game question mark So if the player did lose the game then this Boolean will be true in the default value also here's a tip notice how we keep on pressing compile and then we save our blueprint what I could do is click on the three dots go to save on compile and then select always so now whenever I compile blueprint my blueprint will automatically save for us so we don't lose any of our progress and speaking of saving let's go ahead and let's save all all right now I want it where when does Boolean is created with the event construct we will see whether or not we lost the game also I don't like this comment right here so I can click on the comment button to get rid of it now let's control and drag it into my graph to of course as you can guess be left click to add in an if statement so if we did lose the game then I want to set this text so let's make this a variable that's how I get access to it within my graph and call this text and text go back to graph drag from end text and go set text text the same node we've been using for our user interface and then plug this up like that so the new text will be you lost exclamation points brownie base we need a way to set this Boolean value loss game within our game mode and there are several ways we can do that one way is to just drag out from the user interface and go set game lost and then manually set it like that or another way which is a lot cleaner is to go back to my end screen and have that variable lost game selected and down here within the options make sure instance edible is turned on and expose on spawn is also turned on that will give us this little eye icon which is now visible so that is what this icon is doing right here this icon will allow us to set our variable as soon as this blueprint or widget is created now within our Target game you don't see it yet that's because I have to right click and select the refresh notes so we get this brand new Option where I can set true or set it false now down here when the player wins the game we want to make sure this is okay it looks like this hasn't updated so right click click on refresh nodes I want to make sure that when the player does win the game this is set to false but when the player loses the game this is set to true okay press play counter goes down and then it says that we lost very sad if we restart the game we won so very happy but now we have a really big glitch because our timer was still going down even though we won the game and then it created two end screens on top of each other so we first won the game and then since the timer hits zero we then lost the game so which obviously doesn't make any sense you can't win and lose a video game so that's because we need to make sure is Game Over Control see this and then control V it right after we win the game to make sure that this timer is stopping when the player wins the game and press compile you probably think that this graph does look messy and disorganized because we are repeating the exact same notes we are repeating these notes and then we're repeating these notes the only difference is this lost game is turned off right here and then it's turned on right there so what we could do is combine these nodes into one event that's how we don't have to repeat them so whenever we have logic that is continually repeated you want to add that to an event or a function so let's go ahead and let's create a custom event and this one will be show and screen now again highlights all these nodes press Ctrl C and Ctrl V it right there so we will hook it up that's how the first node is setting the is game over to true and then the only difference is this lost game so just like within my UI graph we're adding inputs right here we will also add an input to my game mode so let's drag out the lost game hover over this and then let go as a shortcut that's why I didn't have to select the custom event and manually press the plus button okay now that we created an event in my graph I can come up here and delete all those nodes and then drag from here and then go show end screen just like that so we are calling if I double click on it the custom event we just created and because we did lose the game make sure this is set to true and then come down here and delete all those nodes and once again make a call to that event show and screen and set this to false so what we just did was that we could bind all those nodes into and events that's how we only have to show those nodes once and they've all been condensed into its own node we're just making a call to the custom events now technically the main bulk of my games logic is done so if I press play we have a timer and I have to hit all the targets before the timer runs out or if I don't do anything and let's say I just barely missed the last Target then we're gonna lose the game so to recap what we did this chapter we went into the target game and we created a timer that will run every 0.01 seconds this event and this event will first check if the game is already over and then if it's not we will decrement that time update the user interface and then see if that time is less than or equal to zero and then if it is it will call the show and Screen event if I double click it'll just jump to it it's right underneath all that logic and then this will create our end screen and we're even going to tell it whether or not we lost the game so up here we lost our game which means it is set to true and then over here when we check if we won the game then this is going to be left blank to tell my end screen not to override this text with the you lost text congratulations you just created your first game in unreal but there are some additional changes we can add to make it even better because right now it doesn't have game feel it doesn't feel satisfying to play our game and we want our game to be fun because why else would people play it I want to make the gun look better and also have more of an impact when the player fires the bullet that's why in this chapter I will go over how to create your own custom weapon completely from scratch so let's hop back into unreal right now the weapon is built into the first person character so if I open up first person character by going to first person Blueprints and double clicking on it we will see in the viewport that the weapon is built in now generally at least for this case we can leave it within the first person character because we only have one weapon but what if we have a multiple weapons that we want the player to hold then we wouldn't create the weapon within the blueprint instead generally we separate out the weapon into a separate blueprint so that's what we're going to do we're going to take this weapon and create its own blueprint class for it so I can delete it right there and also come down to the arrow and delete it down there because that was being used by the weapon go into the event graph and all this logic right here handles firing we're going to create our own fire logic so I can highlight all those nodes and press delete now if I press compile we are going to get one more error and that's because in the construction script we are attaching the weapon to my arms we don't need this because we don't have a weapon anymore so we could go ahead and delete that and press compile now let's go ahead and create our weapon blueprints so control space and I'm going to create it within my blueprints folder right click go to blueprint class actor and call this BP underscore rifle and the reason why I chose an actor is because this rifle is going to be placed in my world so double click to go into the rifle and here is where we're going to be creating our weapon so to begin we could use unreal's default gun but in my opinion I don't really think it looks nice that's why luckily for everyone watching this video If you downloaded the content Link in the description you'll get the Sci-Fi weapon so if I double click on this weapon this is what we're going to be using and in my opinion it does look a little bit nicer than unreal's default weapon so let's go back at a rifle press control space and drag this onto my default scene route and then let go so now our blueprint has that weapon static mesh but you'll notice that we still get that little icon in the middle which is the default state birds we do not need that anymore so I can hold down the left Mouse button on top of my static mesh hover it over default scene routes and let go so now the only component of my blueprint is the sniper rifle and also this is optional we can even drag in a scope so let me go ahead and drag the scope up here and then let go to add in a scope and we will place the scope right there so this is optional if you don't want the scope then you don't have to add it okay let's press compile and now we created a simple rifle blueprints that I can drag into my world but of course I don't want it just load in here I want it to spawn with the player as soon as the game begins so as soon as we press play this weapon will be spawned and attached to my player's hand and we will do that in the first person character so let's jump back to the event graph and up here we have event being play which will run as soon as my first person character is created right here we are adding our inputs and then I'm going to drag from here and immediately after that logic runs we will spawn an actor from class and of course he's going to ask for a class we're going to spawn our rifle so we are spawning the rifle Blueprints and then it's going to ask for a spawn transform this is asking for the location that we want this rifle to be spawned at this doesn't really matter because we are going to attach this immediately to the arms but for now I can drag out my arms into my graph and then we can get the world transform so this will get the location of my arms in space this is a transform instead of location because transforms also contain rotations and scale and if I drag from the transform make transform and then select it right there we can see that transform just contains our location rotation and scale so that's what that is I could plug that up and then I want to make sure that this always bonds ignoring Collision really unfortunate if the player spawns without a gun and then we're going to immediately attach this gun to a component specifically attach it to the arm component so drag from here and go attach components to components and select the sniper rifle like that because we do not want to attach only the scope to my arms I want to attach the entire sniper rifle and plug it up like that now for the parents we're going to drag in arms once again and hook it up so this is going to attach my rifle to my arms and we need a location on my arms that's going to attach to and that is the grip point and make sure you spell it exactly like this because there is a point on the player's hand called grip points and we're not going to keep relative I want this to immediately snap to the grip points so set this to snap to Target also snap to Target and snap to Target and then press compile so this is what our game would be if we didn't run with it so let me break that and our player doesn't have a gun now as soon as we spawn the gun and attach it to the arms now the player has a weapon so that's how you add weapons and it's great because let's say if we have multiple weapons maybe we have a shotgun then I could go in here and just change it out for a shotgun for the player to spawn with a different weapon alright so we got one big issue and that is pretty obviously if I press the left Mouse button we don't fire the weapon also if I look on the ground the weapon Shadow is showing which I don't want to happen so let me go into BP underscore rifle and select my static mesh components come up here to details and type in Shadow we do not want to cast Shadow right there and let's not cast Shadow right there okay another thing I'm going to do selecting the static mesh is come all the way down here to Collision and set this to no Collision that's because right now our gun will block our world so we might walk up to a wall and then the gun will block the player which is something that obviously doesn't have to happen so select the static mesh again and select that to no Collision so that's not blocking the player okay and now we're going to jump into the event graph we don't need any of these events so delete it we're going to create a custom event so type in custom events and you can probably guess what this event will do and that is it will fire and to make sure our fire event is working you can probably guess what no we're gonna do to debug and that is the print strain so let's go ahead and print string that and then we have to call this fire event within the first person character because this is where we are going to have the left Mouse click inputs so down here right click type in left Mouse and select the left Mouse button so when I press the left Mouse button this pin will be activated and then we want it to call the fire function so I need a reference to the rifle we created and I can get that reference all the way up here so right after we spawn the rifle we need a variable that stores that rifle so right click and go to promote to variable and call this rifle the reason why is that a reference to this actor when it spawned will be outputted right here so this is where I want to store it within that variable and then plug it up so now I can get that rifle hold down control left Mouse button and let go to grab it and then type in fire and we can even see that this is a rifle because down here when the variables for type it's selecting BB rifle and then plug that up so now if I press the play button you see top left hand corner we get hello that's how I know the fire event is working so I can start to add my logic now right here all right so we need to spawn the projectile and we're going to do it the same way that we spawn the rifle by dragging from fire and using spawn actor from a class and we can also delete the print screen since that was just there for debugging so for the class that will be projectile we are going to create our own projectile in just a second and then we need a location to spawn this projectile so of course this should be spawned at the muzzle of the gun but we need a way to indicate that hey it should be spawned here and it should point in this direction and we can do that by adding a component called arrow and keep in mind that the player will not see this Arrow so we're safe so let me go ahead and let's rotate this make sure snapping is turned on 90 degrees exactly and then place the arrow at the very front of the gun this is where the bullets will be spawned and actually let me go decrease the arrow size since it's a little bit too big and place it right here now within the event graph I can grab my arrow and get the world transform right there and plug it up now the first person projectile will be spawned at the arrow so if I press play We Should okay now we're able to spawn our balls just like beforehand but you'll see that there's no impact it's just flying out I want a little animation to tell the player that hey something's coming out the gun so we will do that by playing an animation on the arms but in order to play animation on the arms we need a reference to the player character so let me get player character and then cast to first person character to get access to those arms so now that we have a reference to this blueprint I can drag from here and get the arms components go all the way down here and get the arms okay now I can drag from arms and get the anim instance we need this in order to play animations and then finally drag from here I know there's a lot to get access to the arms but drag them here and do a play Montage so select Montage play and then hook it up like that so it's asking for an animation this animation already comes with unreals default template so select FB underscore rifle shoot montage and then plug this up so this is a lot of nodes but that's okay before we Press Play Let's jump back into my game mode because I noticed that at least for play testing purposes this time is too little so let's set it to a time of 1000. okay press play and now when I fire you can see the weapon recoiling now we should add two more nodes to the fire and that is of course sound and another one is a particle effect so every time I fire there'll be a little bit of smoke and a muzzle flash okay let's go into the rifle and right after we spawn the actor play sound at location and this location will just be our rifles location in our world so I can drag from a location and get actor location so this will get the rifle location and then for sound we already have a sound and that is weapon rifle punch now when I fire we got some sound and we will now spawn a particle effect and this particle effect is a system Sogo spawn system attached the reason why we're using attached is because I want to attach this system to the arrow right here so go back into event graph and the system is p underscore muzzle flash this came with a downloadable content so select it and we can view the muzzle flash by going into sci-fi weapons effects and double click muzzle flash so here is the little muzzle flash we'll be adding to the muzzle of my gun and the components will be the muzzle which is Arrow so attach it like that and we can leave everything as blank so now when I press play when I fire you'll see that we get a little bit of a flash and that flash is even affecting lumen so it lights up my world at this point we are almost done with a rifle what we did was that we took the weapon logic that was right here within the first person character and turned that into its own blueprint that's how if we do have multiple weapons we can switch in between them and if we go to the event graph what I'm doing is that at first when the player presses fire we get that player's arms and then we play an animation on those arms we then of course spawn the projectile and then we play sound at location and add a little muzzle flash so really for this event we could have just gone away with one node and that is the spawn actor we didn't have to add an animation sound or particle effect but then the gun felt stiff it didn't feel like an actual gun it didn't feel fun to Fire and the point of us making a game is to make a fun game so even though it doesn't add any gameplay effects it does look nicer when we fire and it can be a little bit addicting we have one last change I want to make and that is the all projectile because it doesn't feel like a bullet it's a bouncing ball and I don't know any guns in real life that's shoot out a bouncing ball that just completely disappear after five seconds so let's create our own projectile that is a little bit more realistic so control space we will go to blueprints right click create a new blueprint class and this will be an actor because this projectile is in the world space and this is BP underscore bullets double click here to go into it now we're essentially creating a bullet tracer so when the player fires a bullet they'll see a line flying by really fast so we first have to add in a collision so type in Collision that's how this Tracer knows when it hits something so selects your Collision right there and then for the size we want to make this really small so I found a value of 2 to be good so the smallest it could possibly be also we don't need this default scene root so hold down the left Mouse button hover over default C route and let go now we need to also add in a sphere basic shape sphere so this will be a static mesh fear and this is just floating in the air actually let me go show what this looks like if we do spawn it so go to BP underscore rifle and instead of spawning the first person projectile let's spawn the bullet blueprint we just created okay so if I press play and spawn it [Music] obviously that doesn't really look realistic so we need to make that a lot smaller go back into the bullets and within scale I found a value of 0.1 in the x-axis 0.1 Y and a 0.1 Z okay so now if I spawn you know that's a better size but it's just floating in space so we need to add projectile movement and to do that is really easy just come up to the add button and type in projectile so now we're able to add projectile movement to the ball and it's asking for initial speed and a max speed if we put in something like 500 and 500 for initial speed and Max Speed press play now you can see that okay it's firing and it's going into the direction of my gun and the reason why it's going into that direction is because if we go back into the rifle we are getting the arrows rotation so the rotation that this Arrow has is a direction of our projectile because within the world transform if I drag from here and break it contains the rotation also make sure that if your bullet scale is off that's because it's grabbing from the arrow scale so if I go to viewport and select the arrow I could have scaled it up with the scale Gizmo which would actually change those values there and it is those values which will then be fed into the spawn actor which the spawn actor will then use because it's getting the world transform so to prevent that from happening I scaled it within the arrow components that's how it won't use that scale value now let's jump back into our bullets and of course this has to be a lot more than 500 I found a value of 13 000 to feel like a bullet of course feel free to change these maybe you want your bowl to be faster or slower but this is what we have now so just buyers into the air and this looks great but it doesn't feel like a bullet because if you've ever seen tracers in real life then you know that they have an emissive value to them because they light up the world so to make our bullet emissive we need to add an emissive material luckily for you within sci-fi weapons materials we have M underscore emissive bullets so if I double click to go inside of it this is the material it's really simple it's just being fed a color into the emissive color and if you want to learn how to create your own materials you can check out the other ue5 beginner tutorial where I go over materials and environment design in Dev so let's go ahead and let's make sure that our sphere is selected and then drag this onto the material slot and let go now this feels this feels like a bullet so I can fire and everything is working great except when I try to fire into the target it's not working and that's because if we jump back into my Target Blueprint by selecting it and pressing Ctrl e to edit it you'll see that uh oh we're checking if a first person projectile is hitting it not if a bullet is that's a simple fix drag from actor and go cast to VP bullets and then select that and delete it okay so now this will work where if I compile go back to first person map press play now if I hit it you can see it is still not working and that's because we need to make some adjustments to my bullets Collision so number one this sphere that we have right here I don't want that to collide with anything that's just there to make our bolus look more aesthetic it is this sphere so the Collision sphere which will handle my Collision so let me press Ctrl Z to move that back into the middle and with a sphere selected make sure for Collision presets it is set to no Collision but for the sphere this is set to block all now this should work now if I hit a Target the score increases one two three four we won the game but you'll see that when I do hit it the bullet just sits there or if I hit this the bullet isn't being destroyed and that just looks really weird maybe that's good if you're creating like a bow and arrow but in our case I want the bullet to be destroyed when it hits something so this is where we're finally gonna jump into the event graph we haven't even edited anything yet let's delete all those and select the sphere scroll all the way down and on component hit so when this does hit something we will drag from here and it will destroy itself so select destroy actor okay so if we hit it it just disappears like that but I don't want to disappear instead I want it to shoot some Sparks and leave a bullet hole So within the bullets before we destroy it I want to spawn a system at location so we're going to spawn another particle effect just like how we're spying a particle effect for the muzzle right here and instead of spawning system attach because we're attaching this to the muzzle we will just spawn it at location and this will be the other effect that's within sci-fi weapons effects and that is p underscore projectile Sparks so go ahead and select that right there now it's asking for a location and we could get that location by dragging from Hit And typing in break so it contains a bunch of useful information on the component that the sphere did hit and if I select this Arrow to bring down the drop down we get all this information so it looks intimidating but we're only going to use some of it and that is we're going to use the hit location so drag location right there and then we need a rotation so in which direction are the Sparks going to fly because if I press play now let me come up to this wall you'll see that it's spawning in the wrong direction it's going to the right I want it to spawn in the direction that the bullet hit the wall so let's go into bullets and I can get that direction by dragging out of impact normal so impact normal will give the hit Direction and then I can hover over rotation and let go so even though this is a normal you could convert that into a rotation and now this should work so press compile and when I hit something okay we can see the Sparks are going in the direction of the wall and we also of course we need to hook it back up to the destroy actor now when I play my game and I fire my weapon It's Gonna Leave a bullet hole and shoot out Sparks in the direction of the wall so we can even see all the bullet holes that we're creating and it looks pretty nice so if I restart the game get one two three and four and we won so now our gun and our bullet feels a lot nicer than the default unreal weapon we do have one big issue and if you had an Eagle Eye you probably notice it and that is our bullet doesn't go into the direction of our Crosshair it doesn't go into the middle of the screen instead it's random or it depends on the animation of my gun I want to wear when I point at something the bullet will go directly to where the Crosshair is point at so if I'm pointing into the middle of this grid and in fire I want to go into the middle of the square not off to the side the reason why this is happening is because if you go back into the event graph of my rifle we are using the rotation of my arrow which is attached to the muzzle that means even during an animation when the muzzle is a little bit up then our bullet will be fired in that direction so we get kind of like a recoil effect where the more we fire the less accurate it is or maybe you want that to be intentional kind of like recoil control in CS go but in our case I do want to get rid of it jump back into BP underscore rifle and go to the event graph and instead of using the rotation of my arrow we will use the rotation of the first person camera so whatever my camera is looking at is where the bullet is going to go which is also where the middle of the screen my Crosshair is pointing at so go back into BP underscore rifle and luckily for us we already have a reference to the first person character right there so I can drag from here and go get camera and go all the way down here to get the first person camera now I'm going to drag out and get World rotation okay so I want to use this rotation the only issue is I can't just plug it up right there because it's a transform and a transform contains the location rotation and scale so what I will do is drag from the transform make transform and then select that so now that we have access to the location rotation and scale individually I can use the first person camera's rotation and then of course I still want to spawn my bullet at the muzzles location so I can drag from Arrow and go get World location right there and then plug this up okay we don't need the world transform so I could delete that and now when I play my game and then if I look at the middle of my grid right there and I fire my bullet will go into that direction and we no longer have that issue where the more I fire the more recoil we have again if you did like that feature then you could leave it in but in my case I want to make it as accurate as possible now that the gun feels great to fire we need to add impact since with a bullet hits the target there's nothing to tell the player that the target was hit they have to check their score and see if the target was hit that makes our bullet feel weak normally with a fast moving object hits another object it destroys it so that is what we're going to do right now we will use chaos physics which is unreal physics engine to destroy our Target into a bunch of different pieces before we go over how to destroy objects we need to cover the very basics of physics in Unreal Engine so right now if I drag in SM underscore targets Loop this around and if I press play Turn Around by default objects are just floating in space they have no physics in order to tell unreal hey I want to add a physics object we need to go into the details panel and down here under physics select simulate physics now when I press play that object has physics it fell to the ground and I can kick it over and you can see its physics flying and here's another tip notice how I keep on having to play my game in order to see the physics in my world what I can do instead of playing the game which will possess my player character if I still want to fly around like normal in the editor within the drop down up here I can select assimilate or the shortcut is alt NS instead of playing my game so now if I simulate it then we are assimilating my world I can see the physics but I can fly around my world and still make edits like normal so I can move this box down and then I can use this box to knock over that Target when I'm simulating my game not every object can be moved the reason why we were able to move this box was because it is set to movable and also we set to simulate physics as soon as I turn on simulate physics on an object that will be set to movable unreal's default Behavior if I add in let's go add in a sphere unreal's default behavior is to set it to static that means throughout the duration of the game or when we're simulating our game this object will never move and we can even see that in action if I press simulate I'm unable to move this object but as soon as I said it's movable then I can start to move it so I can like knock it down like that and then grab it in X and Y axis and hit like we're playing air hockey so now that I know how to assimilate my world and still be able to move objects to knock over different physics objects let's go over the basics of Destruction and before we destroy an object we first need the object that we want to destroy in our world and in this case is going to be our Target now it's very important before we destroy objects and you want your object to be in the rotation and scale that this object will be when you're reusing it now in our case I did change the rotation make sure this rotation is set to zero zero zero and the scale is set to one one one okay now that it is I can hop over up here to the mode selector and within the drop down we get all these different nodes now we do cover landscape and foliage within the other beginner tutorial but in this tutorial we will go over fracturing so this is chaos destruction this is how you destroy objects in Unreal Engine with this mode now before we can do anything we first have to create a new destruction object by clicking on the new button it's going to ask us where do we want to save this destruction object I want to save it within targets right there and it already gave us a name SM underscore Target geometry collection so objects that can be destroyed in Unreal Engine are called geometry collections so let's create it and now you'll see that this material did change and within that folder we saved it to we have this brand new assets and this asset has a bunch of settings so let me close up for now and let's go over what is happening right here and this looks very complicated now don't worry I always say you're never really going to use any of these tools except for very specific circumstances in my circumstance I just want to add a basic destroy to this mesh so I want to divide it up and to do that I can use any of these fracture tools right here so maybe you want to destroy a brick wall you would select brick but in my case I'm going to use the default of uniform and immediately you will start to see that we are slowly starting to break up my object but we're not breaking up our object just yet because within the fracture tool right here I first have to select a fracture as soon as I select this then this mesh will be sliced up in the direction of these lines and you can always change any of these lines let's say if you want a little bit more then you could come up here and change it or you could just leave it at the default of 20 and then scroll down and select fracture now this will create a brand new window in the top right hand corner and right here you'll see that we now get 20 different individual meshes so these meshes is what our object is going to break into when it hits something and I can even come up here and this is just a preview it's not going to change anything because it's under view settings but if I increase my explode amounts we could get a better sense of the geometry that's being created now this is the first level of Destruction we can add another level by fracturing it again so we need to make sure that we have the root selected up here and then I'm going to select fracture another time so now each of those 20 pieces will be divided into even smaller pieces and coming up here to explode we'll get a better sense of that so we will add another layer so I found that three layers look good you can honestly play Within These values or add as many layers as you like so let me press fracture again and now we have three different layers of Destruction so the first layer will be the first to be destroyed and then after that the second layer and the third layer now let me bring that back to zero and I think we are good so let me press cancel and we will leave fracture mode go back into the default of selection mode and we have this really weird material that's okay within the details panel we can get rid of that by going into General and unchecked show bone colors to get back my original material that material was just there to help us the developers see what the different pieces are okay so now if I simulate it falls to the ground and nothing has happened that's because at least for this object it's hard to destroy it so we could change how easy it is to destroy this object with physics by opening up the geometry collection right here within the contact browser right here so this is where that geometry cluster is being saved that we just created and to make it easier I will uncheck masses density and bring up minimum Mass clamp to one so now if I press alt and S you can see that it was destroyed just a little bit but in order to destroy more I can grab this movable sphere bring it down and then let's smash it I like that so it is really fun I could basically see it be destroyed grab it and then slam it against the wall and see all those pieces fly everywhere kind of reminds me of Gary's Mod I don't want gravity to be able to destroy my targets I want it where when the player Fires at the Target it will be destroyed so let me go ahead and let's rest this target against the wall let's go right here that's how it doesn't get destroyed immediately I want to play my game again so come up here and select the selected viewport that's why I'm playing my game and then when I fire on it I want it to destroy the Target right now it's not doing anything to do that we need to add a force to my bullets so control space let's go back into my first person Blueprints and open up the bullet blueprints so right here whenever it does hit a location I want to spawn a force field in that location and luckily for us unreal is already built in some force field blueprints we can use so let's drag from here and go spawn actor from class and specifically the actor we're going to spawn is FS Master field and select that so this is a force field that comes with Unreal Engine and we can even open up this blueprint to see what it's doing so if I click on this little magnifying glass it will jump to that location in Unreal Engine and notice how instead of it being under the content folder it's under the engine folder this means it's built directly into Unreal Engine so if I double click here is the blueprint so it is really complicated but luckily for us all we need to know is that when it is created it's going to add a force at that spawn location so I can drag from this location and drag it all the way over to spawn transform and let go so this will convert the location into a spawn transform and the transform will have a rotation of zero zero zero and a scale of one which is what we want okay so now if I compile what is happening is that when the bullet hits something it will spawn our particle effects and then it will spawn the force field and then destroy itself okay so if I shoot it notice how there's a little bit of a delay it's almost like there's a one second delay before I shoot it and then it explodes so that is by default built into the master field it doesn't explode immediately to make it explode immediately drag from here and type in CE trigger so this will just trigger it right off the bats and then after we trigger it to make sure that the force field isn't being applied anymore because I want it to just be a burst I will drag from Return value and then destroy the actor so it's created and then it's destroyed immediately and of course hook it up to this destroy actor which is destroying the self to the actual bullet okay so now we spawn on the master field we trigger that field and then we destroy the field and then destroy the bullets press play if I come over here and fire it will be destroyed immediately and I could keep on firing at these chunks to destroy different ones also I know this was a glitch when I look at the floor and then when I fire my player is moving and that's because within the bullets the bullet is colliding with the player character something we don't want to happen so select the sphere and then within in the Collision preset drop down change it from block all to custom and I want to pretty much block everything except the pawn which is our player so that will be ignored okay now if I press play we don't have that glitch but we can still destroy targets and increase our score okay we're gonna bring this geometry collection we created and add it to the blueprint right here so we can select any of my target Blueprints and press Ctrl e to automatically edit them now within the viewports instead of using the static mesh targets we're going to use the geometry collection targets that was in Target right here and also let's save everything so we don't lose our progress okay so I'm going to delete that static mesh and select yes it's giving us a warning because we are making a reference to it right here I can delete that too and then add a geometry collection and within here for the rest collision and let me dismiss that to get rid of it for the rest Collision drag in the geometry Collision we just created and let go so now we have it but there is a big issue when I press play it just Falls and they start getting destroyed something that shouldn't happen so by default within the targets for the geometry collection we will go down to simulate physics and they will not simulate physics to start with so if I press play they won't fall and crumble now jumping back into the targets we need a new hit Collision that will then activate all this logic because right now we don't have any events hooked up to it so to get that Collision let's create a brand new one and it will be a box Collision so the Bullet will have to hit this box and let me make it it's a little bit smaller like that so that it's encompassing the majority of the target like right there and also within the geometry collection make sure it's set to block all just in case so the pieces don't fall through the floor now with box selected I want to set this also to block all so it will be blocking my bullets and select on component hit like that now we're going to hook up this event to my nodes so when this box is hit we're gonna see if it's a bullet let's double check this is working press play one two three and four okay so this is working great now this is the part where we add in physics so if this is hit and it's the first time being hit then we will drag out the geometry collection and we will set simulate physics to true so now we want it where it can fall to the ground but it won't fall to the ground because remember as soon as a bullet hits something then we spawn a force field okay so if I hit it it would be destroyed so this looks really cool now with my targets but we do have one issue and that is if I destroy a Target and then try to walk through it the player is getting blocked so after that Target is destroyed we need to get rid of that box Collision right here after we set simulate physics and before we add the score let me move it I will drag from box and go set Collision enabled and then set it to no Collision so that will allow the player to go through the targets or the bullets to also go through the targets and we didn't have to hook it up right here we could have also hooked it up at the end of that score the ordering doesn't matter for this logic so let's press play again and now if I fire I can go through it and it won't be blocking the bullets and there's one last change I want to make if we destroy something you'll see that okay the interior of my mesh doesn't have a material it just looks really weird that's because we need to set a material to the interior of the mesh so we don't get these plain colors and to do that we're going to go into the target blueprints go back into the viewports and make sure we have geometry collection selected now element 0 will be our main material this is the material that we can see but element 1 will be the secondary material so this is the material that's inside and right now it's set to the wrong one so luckily for us if we go into the target folder I have this other material called M underscore Target interior so this one is pretty simple it's just a texture that will go inside of the wood so let's drag this and place it right there and now it is filled up so that was a small change but it does make a difference where if the player really inspects it it looks more natural and that is the very basics of how to program a game in Unreal Engine using blueprints so now that we have a nice game there is one more issue and that is the environment the world of our game is very boring it's just the default first person map which is a bunch of Cubes now we are going to go over how we can take that game that we created and migrate it over to any new environment that we choose this part will be really fun but before we begin I highly recommend if you are a complete beginner to watch my other beginner tutorial that focuses more on level and environment design where you will learn how to create your own environment completely from scratch in that video we create this environment you see on screen if you did follow along with that tutorial you could use that environment for your game for example here I took the castle forest and Scattered my targets around which will force the player to explore and see what you created now if you don't want to create a world then you could pick any environment that is available to us on the marketplace you can go to browse and then select environments or unreal comes with a bunch of free content we could use under the samples page so here we get a bunch of environments that we can select from in my case I'm going to select the electric dreams environment because I think this looks the nicest you can see it's a jungle now keep in mind this project is really a tends to run so if you can't run this project then you could pick a simpler one from the samples page so let me go ahead and select that and to create a project select that you could give it a name and a location to save it in I'm just going to save it in my desktop and press create it might take us a while to create this project because it is 60 gigabytes large keep in mind you don't have to follow along with the electric dreams demo this exact same process applies to every other environment so now that we have it downloaded it will be on my desktop just double click to open it up and then open up the EU project if this is your first time opening up the project then it may take a while for the shaders to compile right here we have the recommended specs so you can go ahead and look at this and if your computer is less than the minimum specs then I wouldn't recommend running this project but if you do have a project that's not that powerful we have two examples so we can either open up electric dreams environment which is the full demo or we can do PCG close range which is a lighter weight smaller environment that's easier to run so let's go open up PCG close range by going to levels PCG and selecting PCG close range okay so here is the smaller environment that you could use or if you have a strong computer we can open up the main one under levels which is electric dreams underscore EMV and this is what we will see and it's really intense to run if I press Ctrl shift and H then in the top right hand corner I can see the frame rates and right now we're around 30 frames per second on a 30 90. so yes this project is a tense but it is the nicest looking project in Unreal Engine and here's a good example we see all these editor widgets if you want to see what the environment looks like by itself so what the player will see then press the G key to go into game View mode so I'm going to leave it in game View mode for now and press Ctrl shift and H again to get rid of the frame rate counter so this is our environment and it is really amazing we can even Zoom all the way out and it's an entire world we can look at so unreal created this demo to show off PCG which is their procedural tool framework and there will be a tutorial and different packs in the future that go over the procedural tools so don't forget to subscribe to check those out now let's go back to where we were right here and if we want a clearer view without these windows you can press F and 10 to hide those windows and then if you ever want those windows back I can hover over it and click on it to individually bring out each one or I can press F and 10 again so that's a shortcut to hide them and we right now have controls for our player that's because if I press play it will automatically spawn Us in as a drone a lot of these environments come with a default game and a default player controller so this is that controller it is almost exactly like the unreal editor controls except we get smooth movement now I do not want to use this player character of course I want to bring in the game that we've been creating and add it into this environment so let's press escape to get out of the game and let's select the text because it's in the way and to get rid of it press the delete key you want to open up the project where we created our game in my case I named it my first game and then within here purchase control space and get the blueprint that contains all your game logic and in our case of course that is under first person Blueprints and it is GM underscore Target game so this is the blueprints where we made the majority of our logic now let's exit out and right click on it then go to asset actions and select migrates so unreal will be smart enough to go through my entire project and find all the assets that this game mode is referencing so that includes our player character we can go up here to first person Blueprints and see that our player character is being selected our bullet our rifle and all the assets that These Blueprints are using so the static mesh for the rifle the mesh for the Target and all of its materials which is nice so that's why we don't have to worry about or maybe we migrate it and then we miss an asset so let's click on OK and then navigate to location of your environment project in my case it's just on the desktop and select the content folder and then select it so this will copy and paste those assets into my main environment and right now it's using the default game of this project and we can see what that is by going into World settings and game mode so it's GM underscore anim sandbox of course we want to change this to the game mode that we just migrated over if I press control and space which was under first person Blueprints and it is this one right here so GM underscore Target game is what we copied over so go back into your world settings and select GM underscore Target game right there so now if I press play instead of getting the Drone we get the first person player character and I can walk around and fire like normal and also I think my time is a little bit too short so let's go back into my game mode and select GM underscore Target game to open that up right here and then let's change the time to something a little bit larger like five thousand okay so this is really fun all this time we've been making a player character and now we can see what our player character will feel like in an actual environment so we can explore this environment with the weapon that we programmed I could go around and I could just start firing a random vegetation and rocks and I can't go over this so I'll have to jump over that log to continue exploring okay so score was zero out of zero of course that's because we don't have any Targets so let me go ahead and let's set up a shooting range within this location also we don't need a sphere this fear shows off unreal's new material system called substrates which there will be videos on in the future but for now I can delete that sphere because it is in the way and it's kind of a random so let's press Ctrl space and let's add in a Target over here rotate this scale it up turn off snapping because that was enabled and if I press play I will spawn at the wrong location because the player's start is right over here so let me press the G key to go out of game View mode and I can see that the player start is right there I could move it over there or I can delete it and then manually come over here to place the player start down within this area so let's go to add button basics player start and drag that in and make sure it's rotated in the direction of my targets and then press play now I'm playing my game I can destroy these targets each one and then we have one more all the way over there so I'm gonna have to fire on it and we won we don't have an issue with this environment but sometimes the bullet will be blocked or the player will be blocked because the player Collision on my world is different from what the player thinks the Collision will be so we can always see what the player Collision is by going to lit and selecting player Collision now luckily for us in this environment it doesn't look like that we have any Collision volumes blocking my targets so in this case we're okay but let's say you're in a different environment and we can shoot these targets we have no issue but if we try to shoot the target up here you'll see that our bullet is being blocked and that's because if we go into the player Collision of this level you'll see that the Collision box is blocking the bullets from hitting the targets so in order to fix this Collision I can select that static mesh as a whole press Ctrl and E to open up its editor and then if we scroll down all the way to Collision instead of selecting project default we're going to select use complex Collision as simple now if I jump back into here and go into my player Collision you'll see that our Collision is the actual geometry of the mesh which means that this shouldn't block my bullet anymore I am able to hit that Target and continue playing on like normal I'll be back into our game environment it is now finally time to finish our game and honestly this part can be really fun we aren't even going to open up any blueprints we're not doing anything complicated all we're doing is that we're moving our targets around creating new targets and just trying to make our game as fun as possible and also trying to adjust how challenging it is depending on how many points you want to give the starting countdown timer so I'm going to leave it at 5000 but we are going to change that in just a moment so here what I'm going to do is let me bring this target all the way over here and then duplicate this hold down alt and here's a tip whenever I'm moving an object around I can hold down shift to lock my camera to it that's how I don't have to move it and then move my camera and move it again I get to slow down shift to lock it there so let's go move this target all the way over here then decrease its size add another Target up here and finally for the very last targets let's bring it to this little area you see where that kite is Let's Make a massive Target something like a ridiculous size and then just place it here for the player to hit and you notice that at least the way I'm saying up this level is that the targets are naturally leading the player so the player starts here and then they're going to be led all the way around this rock formation until they end up with a big Target right there so now what I'm going to do is play my game once and pay attention to how fast I can beat the game so let's press the play button all I'm doing right now is that I'm play testing my game to see if the game is fun and if the location of the targets does make sense so we have one right here that I can break and notice how there is a really long stretch right here of nothing maybe I should add in another Target there just to entertain the player so that they always have something to shoot that one and then we have the last Target massive all the way up there hit it and then it will be destroyed slowly it's kind of like an avalanche and notice how we beat this with a time of 2000 200 out of 5000. so that gives me a good sense of what I can change the countdown time of my game to be so I could change the time by selecting right there or selecting the time variable so right now it's set to 5000 we ended around 2 000 so let me try 2500 so let's see if that would be good by going back into my map and selecting the play button so this should be the last time we play our game this is the final product now we gotta race against the time so shoot that one that one at this target we have a Target on this path that I could hit and I could hit the really big Target right now the fire on it and it's really cool to watch that physics it does look like an avalanche we have one target right there and finally one last Target all the way over here sorry fire on it and we win the game so congratulations you just created your first video game in Unreal Engine and we did it pretty quickly we had a time of 75 left so I think that was a good time to lead the game at congrats on creating your first game in on real ninja 5. you got something out of it make sure to subscribe because I have a lot of cool videos playing for this YouTube channel I also have a new course called the unreal game developer in it we take an even deeper dive into blueprints you will learn everything there is about programming and game creation we even create a full game completely from scratch you will see the entire process from Concept in a game to uploading it onto the internet you can check it out Link in the description below and with all that being said I hope to see you in the next video
Info
Channel: Unreal Sensei
Views: 151,239
Rating: undefined out of 5
Keywords: ue5, beginner, tutorial, unreal, engine, unreal engine 5, unreal engine 5 beginner, course, free, 3d, game, nanite, lumen
Id: 1XjgLKrb4_M
Channel Id: undefined
Length: 159min 4sec (9544 seconds)
Published: Wed Aug 23 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.