How To Set Up A Respawn System In Unreal Engine 5 (Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another unreal engine 5 tutorial in today's video i'm going to be again advancing upon my previous tutorial with something which i said i do and that is a respawn system so this means the player can now actually die using our system we created last time and when they die they will also respawn so let me hit play and show you what i make today so previously we've created the health bar and we've created a system which we can take damage and we can also heal as well like so and now once we take enough damage what's gonna happen is the player is going to actually die and they will then also respawn so we've died a second later we're going to respawn like so so you saw after a second we then respawned here like this and with the system you can also set another respawn point so if i come over here press five as that's just what i've got it set up as for the purpose of the tutorial and then we were to die again our respawning point should now be set over there we will respawn as you can see here and it also keeps the rotation as well as the location and that's very easy to customize and set up so it could be a checkpoint you walk into something and it then set your spawn point there very easy to set up an advanced pawn and this is what we're going over and creating today so without further ado let me delete this code and i'll show you how i've done it so the first thing we want to do is we want to actually open up our game mode blueprint so we're going to go to control space to open up our content browser third person blueprints and bp third-person game mode now if you have your own custom game mode which you're using feel free to do it in there just essentially do this in your game mode blueprint and once we're in here we're going to right click and add a custom event naming this one respawn player in this respawn player what we're going to do is add an input with this being named player so we know which player we want to respawn and the object reference for this or the variable type sorry is going to be a character object reference like so after the execution pin of this custom event we're going to get spawn actor from class and now this class wants to be our character but how do we get an actor class from a character object reference what we can do is drag out a player and get class very simply like so and then just put the retirement of that into the spawn actor like so it's that simple then we just need to define where we want to spawn the player so we can right click on spawn transform promote it to a variable and i'm just going to name this respawn transform as a respawn transform and bob stronghold it's that simple we can now compile and save this and that is now going to respawn the player however there's one extra step we need to do in here because this will respawn the player however it won't give control over to the player so to do that we can right click get player controller like so and after the retirement of this get a possessed node connecting that into the spawn actor and the return value of the spawn actor is the in pawn of the possessed there so now we're going to be respawning the player which we define at the defined location and then we're going to be possessing it so we can also control it it's that simple so we can compile and save that now what we need to do is call this event input the player and also input a spawn transform there so we're going to close the game mode and open up our character blueprint so again i'm going to hit control space and open up bp third person character here like so now what we want to do in here is go over to the functions tab under my blueprint here and we're going to override the destroyed function so when the player dies we're going to do destroy actor as you normally would and so we're now going to override what that destroyed active function does so what we want to do is we want to cast to the third person game mode or the game mode blueprints you just used the object is obviously going to be get game mode very simply like so and all we want to do out of this is add third person game mode we're going to respawn player very simply and this player input we have here wants to just be get a reference to self so it is this current player that we want to be respawning and the reason we've done it like this is this then means you can use multiple players or multiple blueprints whatever you can have it unique to each individual character so we can compile and save this because that obviously just means you don't have to cast to individual characters in the game mode you do like this it's a lot more efficient so that's now going to respawn the player all we need to do is actually kill them now so if we go over to our damage system here if you followed on from my previous tutorial you should already have this and obviously if the health is equal to zero that's true they're going to die all i want to do now is destroy actor like so let me straighten that up and that is now going to destroy the actor which will call this function override we've just set up down here to then respawn the player one final thing we need to do is set the spawn point i'm going to do that off of event begin play so what i'm going to do is cast to my third person game mode once again with the object being get game mode like so and then as bp third place in game mode i'm going to set respawn transform or respawn point whatever you named it and the reason transform is just going to be get active transform so when the player spawns into the level where are they currently what's their current rotation and what's their current scale that is then going to be where and how they have respawned later on and if you want to set this up on a checkpoint system you would just do this code here that is selected inside of that checkpoint so when they overlap a box collision for example you just do this cast button set the respawn transform to the current axis transform of the player very very simple so again what i'm going to do is just get the five keyboard event plug that into there just so i can test this out to make sure it works in other locations as well so if we compile save and hit play we should be able to test this out and see it working so let's just walk over here stand on top of here and face this direction hit five my respawn point should now be set there if i come over here and just die to this box we should see that the player will die the act will be destroyed and i will then be spawned over there very simply like so and you'll see that was instantaneous there was no delay on that if you want to delay what we can do is go back into our game mode blueprint and after the respawn player before the spawn actor we can just get a delay and in here you can put any duration you like for example two seconds so let's test that out again let's walk over here press five let's die over here we should spawn there after two seconds of dying as you can see here like so so this works perfectly so i think that'll be at this video as we've done everything we want to do what we've done is we've set up a system in which using our damaging and healing system from last time the player can now actually die and after they do die they will respawn in a place which we have to find by pressing any button we want or using a checkpoint system however you've got it set up so thanks so much for watching this video i hope you enjoyed it and i hope you guys and if you did make sure to like subscribe down below so thanks so much for watching and i'll see you in the next one [Music] you
Info
Channel: Matt Aspland
Views: 49,087
Rating: undefined out of 5
Keywords: ue4, unreal engine 4, unreal engine, tutorial, ue4 tutorial, unreal engine 4 tutorial, how to make a game, how to, ue5, unreal engine 5, unreal engine 5 tutorial, ue5 tutorial, checkpoint, checkpoints, check point, system, respawn, re spawn, re-spawn, res pawn, transform, location, blueprint, blueprints, set, automatically, video, docs, ue5 checkpoints, ue5 checkpoint, ue5 respawn, die, dead, death, destroy, destroyed, actor, on, event, at, rotation, automatic, ue5 respawn player, ue4 respawn player
Id: PwDHGhdDG_k
Channel Id: undefined
Length: 7min 38sec (458 seconds)
Published: Fri May 20 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.