How To Setup Multiple Checkpoints And Respawn At Them - Unreal Engine 4 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back to another religion 4 tutorial in today's video i'm going to be showing you how to set respawn locations and make your character respawn there when they die so i won't really be showing you how to kill the player in this one obviously i will do a very simple killing just to test it but this is basically just going to be you can set the checkpoint location and then it the player will respawn there so i'll show you what this is going to look like now so you can see we have our player if we walk into this checkpoint here we die we should respawn back here like so so that's where we went into the checkpoint and we have this checkpoint here and if we die we should go back to this checkpoint again if we go over here we'll go back to that last checkpoint instead of the other one so let me just delete these and then i'll get on with it and also to do this i'm going to be basing off of the unreal docs for respawning but i'm going to be improving on it and adding my own little stuff to it such as the checkpoint system so now that i've deleted that i'm going to show you how to do this so what we're going to do first is open up our game mode so for me this is my third person game mode which is in content third person bp blueprints third passing game mode but this could be anything that you have as this is just essentially the game mode you have for your game now if you don't know what this is you have the world settings down here you should see game mode override so if you've changed it to something different it will be here but if you've still got it as non it will probably be third person or first person game mode so like say open that up also i should mention if you don't have this event graph here when you load up your game mode up near the top there should be some blue writing saying open full blueprint editor if you double click that or just click it once it should take you to the event graph what we're going to do is firstly we're going to get an event begin play so we just right click and get event begin play like so and we're going to cast to our character so for me this is the third person so i'm going to drag out and cast to third person character like so with the object wild card as get player character again this could be first person or whatever you've named it essentially just the character you are playing as and you want to respawn so now this we're going to bind an event so we're going to add third person character bind event to on destroyed like so plug that into the cast like so with the target of our style passing character i'm going to drag out the event and add a custom event like so and you can name this whatever you want i'm just going to call it on destroyed like so and again make sure that that is plugged into the event there and out of this we're going to get a delay so we can hold down d left click to get delay like so and i'm going to set this to two seconds but you can set this to wherever you want this is essentially just how long it will take to respawn so when the actor is destroyed two seconds later you will respawn so that is what you would change here for whatever you want that time to be so now the delay this is where we're going to actually respawn our character so if we just get spawn actor from class this top one here spawn actor from class and our class is going to be the character we want to spawn so again for me that's the third person character like so and now the spawn transform is essentially where the player is going to be so a transform includes location rotation and scale so this will be where the player is which direction the player is facing and how big the player is so to do this what we're going to do is over in the bottom here bottom left where we've got variables we can hit plus variable and i'm going to call this spawn transform or spawn location anything like that that you want but this makes the most sense for me so then from a variable type up here we're gonna change it from boolean to obviously a transform like so and we're gonna plug that in there like that so the spawn transform goes into spawn transform there and then you can change the collision if you want to always spawn so default always want ink no collisions try to adjust location so basically that means it's going to spawn inside an object it will try to move it but it will still always be spawning even if it can't move it try to adjust but don't spawn if colliding is basically if it's inside something so it's colliding it will try to move if it can't move out of that it just won't spawn or you can have it as do not spawn so default works good for me and then out of this we're going to actually possess this character so that we actually spawn it and can take control of it so to do that if we right click and get player controller like so as this is what is going to be controlling the character drag out the return value and get a possessed node like so plug that into the spawn actor like so with the return value of the spawn actor going to the in pawn of the possess essentially meaning that the spawn the actor that we spawn hence the third person character is going to be the one that we start controlling and possess therefore we can actually control it and then what we're going to do is we're going to come back up to the start up here so just above event begin play we're going to right click again add custom event i'm going to name this respawn like so meaning that when we actually respawn the character it's going to do this again so plug that into the cast so when we respawn it's going to recreate this event here so we can respawn once again so then come back down off the possess and we're going to then call that respawn that we just made so if you right click and just get a respawn like so and plug that into there like that and now we can respawn the character as well and you might be able to do that before the event but that works well for me so now we have this this is what your code should look like so when we begin the game and when we respawn we're going to cast to our character we're going to create the custom event for on destroyed when the character is then destroyed hence dies it'll wait two seconds or however long you want it will spawn our character in the last checkpoint location we have and we'll then start controlling it and then obviously respawn so we can compile save and close that as that's all we need to do with that for the moment so now what we're going to do is actually create our respawning blueprint so what we can do is right click go to blueprint class create an actor i'm just going to call this respawn underscore bp for blueprint and we can open that up straight away so what i'm going to do is add component i'm just going to get a box collision like so change this to how big you want i think this would be good for me and then i'm also just going to get an arrow so if i get another component again arrow i just rotate this to be up and then down in the bottom right where it says hidden in game if i untick that so we can see it in the game what this basically does is it just allows me to see where the checkpoint is so for you you might want to change this to actually be a proper static mesh not just an arrow but for me this is mainly just for testing so i know where the checkpoint will be but again you can put this as whatever you like and do it however you want i'm also just going to scale it down to half size like so so i think that is good for me so now if we go over to the event graph like so what we're going to do is just delete these and we're going to create a begin overlap event for the box collision so if we select the box collision up in the top left right click add event add-on component begin overlap with the other actor we're going to cast to our character so mine is the third person character again this could be first or whatever you've named it what this basically means is that if it's the third person character basically if it's our character that overlaps this event that overlaps this box collision is gonna fire off this code if it's anything else it won't bother so then out of this i'm gonna just come out of the cast we're gonna cast again this time we're gonna cast to our game mode for me that's the third person game mode but this is basically the game mode where you have put all the code that we did earlier the object wildcard as get game mode like so again this is just your game mode that you put the code in and then what we can do is as third person game mode we're gonna set our spawn transform like so plug that in there and this transform is going to be either the location of the character or the location of our box collision so you can choose whichever one you like i'm going to do as a character as there's less chance it will bug out so drag off as third person character of our cast and get actor transform meaning it will just get our transform of our player plug the return value into the set spawn transform so again this is going to get the location rotation and scale of our player and now this should work so if we compile save this we can close it now just to test i'm going to do something to kill the player so if you open up your character blueprint which for me is the third person character again this can be whatever you like i'm going to just find some space i'm going to get a k keyboard event so if i press the k button out of pressed i'm just going to simply destroy actor which is what you do when the player dies so when the player dies you destroy the actor which then fires off our respawn code so again compile and save that now what we do is if we just put in our respawn blueprints and place these wherever we want i'm just going to scale these up a little bit like so i think those two locations will be good now if we hit play we can walk around and test this so if we walk up here that should reset our checkpoint there if we press k the player dies two seconds later we respawn back up here where we first overlapped this box collision if we go down we press k again we should still be spawning here like so and again it kept our rotation so we go out of this walk in this way okay it kept a rotation like that and now if we go down here to this box collision so this checkpoint we press k we die we now swarm back at this box collision again this will keep our rotation location and scale as this is on the transform so now we have swarmed here and if you want it to not be at the edge here that is just because we are getting the player location so you can just make this box collision smaller meaning it will start overlapping when it gets into the center there but this works perfectly so i think that'll be it for this video we've done everything we want to do we've created our respawn system and we respawn at the different checkpoints that we have created around our map and we respawn with our transform so it's the same location rotation and scale so like i say you can put these checkpoints anywhere on your map and they will work perfectly so i think that'll be it for this video so thanks so much for watching i hope you enjoyed i hope you found it helpful and if you did make sure to like subscribe down below so thanks so much for watching i'll see in the next one
Info
Channel: Matt Aspland
Views: 41,793
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, 3d modelling, blender, unity, games design, graphic designer, ue5, unreal engine 5, checkpoint, checkpoints, check point, system, respawn, re spawn, re-spawn, res pawn, transform, location, blueprint, blueprints, set, automatically, video, docs, ue4 checkpoints, ue4 checkpoint, ue4 respawn, respawn at checkpoint, die, dead, death, destroy, destroyed, actor, on, event, at, rotation, automatic
Id: TaGE3e93hM8
Channel Id: undefined
Length: 10min 13sec (613 seconds)
Published: Mon Oct 05 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.