How to Make a Game in UE4 Blueprints: Pickups, Portals, Spawning, Pause Menu

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone so last time we looked at what happened in the main screen now we're gonna look at what happens during the gameplay so today we're just gonna cover all the actors and how we set them up and in the final episode we will basically check how we link all of it together with the game instance so we will be looking at a few things the first one we'll look at is what happens when we pick up coins as you can see several events happened and the coin has disappeared we will look at how portals work we will look at how damage is dealt now keep in mind we have an extensive video on how to make it more advanced than this this is exceedingly basic but basically touch and die and finally we have a heart actor here that you can pick up and it will restore your health so first we'll take it from the top so we'll start with the game mode followed by the player controller followed by the blueprint interface then our first person character then the coin the damage the heal and the portal so to start off let's go with the so the game mode is called at the beginning of every level it is the first thing to appear and it's the first thing that can uh start cascading downwards so here we have an event big in play and the first thing we're going to do is cast to our basic game instance that we created and then set it up as our variable because we're going to call it a few times we're going to remove the loading screen here called from the game instance we're going to create a widget score we're going to add it to the viewport we will cover this in the next episode then when the first person character is spawned we will we will cast to it and we will set its stats based on our save data that is in the custom game instance next we're going to do a branch and this is very important when we load the level we need to know how we come from a portal or have we appeared from a save game state if it's from a portal so the custom game instance will know if we came from a portal the portal itself as we'll see later will will tell itself if we've come from a portal we're going to look for all actors of class portal and for each one of them we're gonna be looking for something in the game instance that has the next uh level entry point if we find this we will then set the player transform to that so basically the game mode will appear the player will appear in the level at a specific coordinate and based on whether or not it was teleported in through a portal or through save state we're going to move the player to the new transform so very important we're going to set the playercontroller to that transform not just a character since we've teleported the player from a portal we need to tell the game instance that that it's done and we're going to clear some variables in it so it will no longer be is loaded from portal and the next level entry point will be set to null if we did not load from a portal it will spawn us from a saved player location so it's going to look at the custom game instance it's going to look in the safe data and in it we're going to get the safe transform from it we're going to do a minor check we're going to make sure that the location is not 0 0 0. this is by default our location in the world so if it is not 0 0 0 then we're going to set the player transform to the saved transform if it is 000 then we're going to use something called a backup transform and it's entirely based in the game instance for the purpose of this the location is minus this much minus this much and plus this much this will be called the first time you load the game because you have neither a saved origin nor portal origin which makes sense next we're going to look at the player controller so the player controller does not have many functions the first one we'll do is on begin play we'll just set the input mode to game only that's because when we go into the game through either portal or loading we want to be able to shoot and get into the action we don't want to have to click and initialize our cursor the other one is the input action for the pause menu which was set as either escape or i believe q in the project this will toggle the pause menu as it is set into the game instance again we will cover this in the future episode afterwards we need to make a blueprint interface for our three different actors one to take damage one to heal health although you could use them interchangeably and one to collect coins again for taking damage and healing health we have another tutorial as linked here where you can go and extensively see how you can do a really really good job at taking damage and dealing with death again for the purposes of this video it's just a counter you can add as many functions as you need here to do as many things as you want notice that the take damage and the heel health are static so there's no inputs or outputs however for the collect coin we have an input which is the guid when we get to our first person character the first thing we're gonna do is go to the class settings where we will add the blueprint interface we've created previously notice that you must compile and save your blueprint interface prior to being able to add it here and once you've added it here you need to compile again and save your first person character in order to have the bpi events appear we then create the bpi events here event take damage event heal health and event collect coin the logic is as follows when we take damage we're going to check a single condition which is are you at or less than zero so when we take damage our health is going to go down by 10. if that value is lower or equal than zero we're going to trigger the death event and that is flagged into the game instance if not we'll just set the health to a new value for the event heal health it's the same thing except that we also check if the upper limit is reached here it's a hundred so if you get above 100 we're just going to set the health back to 100 and finally a bit more complex we're going to do for the collect coin we're going to use the guid input here we're going to add to our coin count we're going to set the new coin count and then we're going to add the guid of the collected coin to the game instances save data so in the game instance we have a temporary save data that we can always transpose into the save game so here we're just building up this guid array if we don't want to save or if we just want to load something else then the data will be lost and then you can basically reset it additionally because we are directly reading from the player character as it is the one that is interacting with the environment we will be setting the character stats and getting the character stats using two functions so to set character stats we basically set them from the game instance and when we take a portal as we will see later we will be getting the stats to set the stats we created a function the input here is a character stat struct the one we've created earlier we're gonna break it and we're gonna get the health the coin count and the character name now it might seem a bit over complicated and why am i setting it twice um whereas you could always have it into the game instance at any point the reason for this is that again the logic here of the architecture is that the character is the one interacting with the environment therefore we're getting and setting it first and if we need to save it we're gonna give it to the game instance later forget it's exceedingly easy get character stats and the return node is again the character stats struct however in this case we split the struct our next actor is going to be the damage actor it has a default scene roots for easy placement so it doesn't clip into the ground a static mesh that is set with a rotating world position offset material that is so we can use the gpu for rotation and not the cpu since we don't need to calculate the vertices movement for more details on that feel free to visit this video where we even benchmarked it and finally a sphere collision so that it knows when it's colliding in the event graph we have a simple event actor begin overlap it will simply check does it implement the interface we have created earlier if so we're going to call the take damage on that same actor and then destroy this actor as you can see there is no method of saving whether or not this actor was taken so if we reload the level it will respawn for the health it's similar to the damage so we have our default scene root a static mesh again we're using the same world position offset as seen in to this video and the sphere collider and the event graph we did the exact same thing as previously shown with the bp damage instead of calling the damage we're gonna heal health that's it finally we have our portal so we used a default particle effect so we have the scene root so that the particle effect does not go into the ground and we have some way to select it we have our collider and the collider we have our particle system it's a summon portal from infinity blades very easy to get and finally we have an arrow now it's very important so the other here is that when you collide with the portal itself you get teleported but if you teleport the person to the exact same location which is the portal it will trigger the portal again so you basically have this infinite loop of portaling to avoid that we're gonna take the portal and when we load into the next level rather than get the portal we're gonna get the arrow set in front of it now this arrow is only visible when you're playing around but not visible in game so you can easily set it on the map and see where you'll be facing when we get out of portal in the event graph we have again begin overlap once we have the overlap we're going to check if it implements the interface and if it does then we're going to call the task on the game instance and in it we're going to do the load level function which we'll be seeing in the next video for the next level uh loading function we need a next level's entry point and then the next level's name these are all variables that have been made public so each portal will have its own entry point number then when you go into a portal it will look for which entry point to go to in that portal and finally each portal have its own level's name which is whatever level it's in this way you can set in the same map multiple portals with each being different exit points and each being different entry points to different levels so let's take a quick look at the toggle pause menu function inside of the game instance blueprint so the first thing you will do is check whether or not we have already toggled the menu if we did then this value is set if not it's null let's go with the not valid option which means you didn't toggle it yet so if you didn't toggle it we're going to set the global time dilation to zero meaning the game will freeze if there's a particle or something in the air it will just float next we're going to disable input from our player character by the player controller this is so that when you toggle inputs and whatever your clicks they're not going to be clicks on the player character or if you need to press keys it's not going to be read into the player character we're gonna set to show the mouse cursor so you can click around we're gonna click create the pause menu widget add it to the viewport if however we toggle the pause menu again and it is valid meaning that we do have a pause menu then we're going to just cancel out of it so we're going to do the reverse from below we're going to set the global time direction back to one we're going to enable our input we're going to hide the mouse cursor we're going to remove the pause menu from the parent we're going to set it as null very important and finally we'll set the input mode back to game only the other function we'll be looking at is the one that portals use so the first thing we're going to check is the save player state so here this is a function we've created so that we basically go into our character the first person character and we get the character stats in it that we've previously set inside the level so every time you take a portal the player character will communicate its health and how many coins it has to the game instance we then set that so we use the get character stats function we've created earlier in our first person character and then we set into our save data variable right here the the variables in question once we save the player's date then we set our next level entry point right here we create the loading screen to mask what's going on and then we're going to set the is loaded from portal to true and then we're going to open the next level now remember that earlier when we created the the game mode the first thing the gamemode will check is have we loaded from a portal if so let's check what the next level entry point is and then we're gonna clean it up and clear it all right everyone we're gonna wrap things up here and in the next video we'll go over the final blueprints required to make it into a fully functional game base thank you again for watching and consider hitting the like and subscribe button for notifications on future videos also consider checking out and supporting us through our patreon see you next time
Info
Channel: Pending Kill
Views: 2,410
Rating: undefined out of 5
Keywords: unreal engine 4, unreal engine tutorial, unreal engine tutorial for beginners, unreal engine tutorial blueprint, unreal 4 tutorial, ue4, blueprints, epic games, game development unreal, unreal game development, ue4 for beginners, unreal engine tutorial 2020, unreal engine tutorial fps, unreal engine 4 blueprint tutorial, bpi ue4, blueprint interfaces, pickups ue4, ue4 health and damage, ue4 health pickup, ue4 pause menu, ue4 level sequence
Id: SEU6AFV7jMA
Channel Id: undefined
Length: 16min 45sec (1005 seconds)
Published: Thu Oct 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.