Player Respawn

17 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€95.97
List Price:  €134.37
You save:  €38.39
£79.80
List Price:  £111.73
You save:  £31.92
CA$139.82
List Price:  CA$195.75
You save:  CA$55.93
A$153.75
List Price:  A$215.26
You save:  A$61.51
S$134.64
List Price:  S$188.51
You save:  S$53.86
HK$778.36
List Price:  HK$1,089.74
You save:  HK$311.37
CHF 89.34
List Price:  CHF 125.09
You save:  CHF 35.74
NOK kr1,107.14
List Price:  NOK kr1,550.05
You save:  NOK kr442.90
DKK kr715.75
List Price:  DKK kr1,002.09
You save:  DKK kr286.33
NZ$171.37
List Price:  NZ$239.93
You save:  NZ$68.55
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳11,945.63
List Price:  ৳16,724.36
You save:  ৳4,778.73
₹8,442.99
List Price:  ₹11,820.52
You save:  ₹3,377.53
RM446.75
List Price:  RM625.47
You save:  RM178.72
₦169,271.38
List Price:  ₦236,986.70
You save:  ₦67,715.32
₨27,777.22
List Price:  ₨38,889.22
You save:  ₨11,112
฿3,446.26
List Price:  ฿4,824.91
You save:  ฿1,378.64
₺3,454.90
List Price:  ₺4,837
You save:  ₺1,382.10
B$580.04
List Price:  B$812.08
You save:  B$232.04
R1,811.35
List Price:  R2,535.96
You save:  R724.61
Лв187.69
List Price:  Лв262.77
You save:  Лв75.08
₩140,436.95
List Price:  ₩196,617.35
You save:  ₩56,180.40
₪370.16
List Price:  ₪518.24
You save:  ₪148.08
₱5,893.31
List Price:  ₱8,250.87
You save:  ₱2,357.56
¥15,475.45
List Price:  ¥21,666.25
You save:  ¥6,190.80
MX$2,042.64
List Price:  MX$2,859.78
You save:  MX$817.14
QR364.56
List Price:  QR510.41
You save:  QR145.84
P1,367.06
List Price:  P1,913.94
You save:  P546.88
KSh12,945.58
List Price:  KSh18,124.33
You save:  KSh5,178.75
E£4,964.52
List Price:  E£6,950.52
You save:  E£1,986
ብር12,237.67
List Price:  ብር17,133.23
You save:  ብር4,895.55
Kz91,290.87
List Price:  Kz127,810.87
You save:  Kz36,520
CLP$98,658.13
List Price:  CLP$138,125.33
You save:  CLP$39,467.20
CN¥724.22
List Price:  CN¥1,013.94
You save:  CN¥289.72
RD$6,024.63
List Price:  RD$8,434.73
You save:  RD$2,410.09
DA13,426.15
List Price:  DA18,797.15
You save:  DA5,371
FJ$227.57
List Price:  FJ$318.61
You save:  FJ$91.03
Q771.64
List Price:  Q1,080.33
You save:  Q308.69
GY$20,913.50
List Price:  GY$29,279.73
You save:  GY$8,366.23
ISK kr13,966.60
List Price:  ISK kr19,553.80
You save:  ISK kr5,587.20
DH1,005.63
List Price:  DH1,407.93
You save:  DH402.29
L1,821.98
List Price:  L2,550.85
You save:  L728.86
ден5,904.20
List Price:  ден8,266.12
You save:  ден2,361.91
MOP$801.48
List Price:  MOP$1,122.11
You save:  MOP$320.62
N$1,812.81
List Price:  N$2,538.01
You save:  N$725.20
C$3,678.31
List Price:  C$5,149.78
You save:  C$1,471.47
रु13,500.25
List Price:  रु18,900.90
You save:  रु5,400.64
S/379.05
List Price:  S/530.69
You save:  S/151.63
K402.47
List Price:  K563.48
You save:  K161
SAR375.40
List Price:  SAR525.58
You save:  SAR150.17
ZK2,764.29
List Price:  ZK3,870.12
You save:  ZK1,105.82
L477.77
List Price:  L668.90
You save:  L191.12
Kč2,432.37
List Price:  Kč3,405.42
You save:  Kč973.04
Ft39,496.05
List Price:  Ft55,296.05
You save:  Ft15,800
SEK kr1,103.50
List Price:  SEK kr1,544.95
You save:  SEK kr441.44
ARS$100,374.93
List Price:  ARS$140,528.92
You save:  ARS$40,153.99
Bs690.75
List Price:  Bs967.07
You save:  Bs276.32
COP$438,931.09
List Price:  COP$614,521.09
You save:  COP$175,589.99
₡50,918.63
List Price:  ₡71,288.12
You save:  ₡20,369.49
L2,526.16
List Price:  L3,536.73
You save:  L1,010.56
₲780,388.98
List Price:  ₲1,092,575.79
You save:  ₲312,186.81
$U4,261.82
List Price:  $U5,966.72
You save:  $U1,704.90
zł416.31
List Price:  zł582.85
You save:  zł166.54
Already have an account? Log In

Transcript

Welcome back everyone in this video we will be creating the script to respond our player back to the start of the level whenever they die. Now this will be one of the more difficult videos we are going to get through, but we will get through it together taking it step by step. First thing we need to define after our player dies is where are they going to respond. And to do this, we're going to be accessing our BP game mode gameplay, double click on that guy to open them up. And within here, we're going to create a variable and this variable is going to be called respond, transform. And I'm going to change the variable type here to be a transform.

Now if I compile over in the Details panel, we can see that a transform is made up of location, rotation and scale data. Now, we don't really need scale data, but we are concerned about the location of our player being respond as well as the rotation. We're not going to actually set any defaults here just yet because we're going to be doing something a little bit more intricate. What we're going to do is set this variable from our First Person Character Blueprint so jump on over to your first person BP folder blueprints and access your first person character. And in here, we need to find our Event Begin Play and if you can't find that you can simply right click, type in Event Begin Play. And there mine is mine is currently hooked up to some motion controller, VR type stuff.

And what I'm going to do is drag this out like that. This because I want to use my Event Begin Play for more than just this little bit of script that it's already hooked into. So pulling it back like this. I can drag out a wire and bring in a sequence node like so. And I'm actually going to hold down Ctrl and left click to place this wire into the bottom most than one output pin. Okay, so with that done, I'm just going to move this up a little bit.

And what I'm going to do is I'm going to right click and do a search for get game mode. And we were just within our game mode gameplay. So I'm going to drag out of this and do a cast to our BP game mode gameplay. And I'm going to hook in the ven zero pin into that and out of our game mode gameplay I'm going to say let's set respawn transform. Again, when we cast we can access any of the functions and variables that live within that particular blueprint. So we're going to set our respond transform like so.

And now we've just got to determine what do we want to set our response transform to be well, if I just right clicked down here, I can get actor transform. And the target for this is ourselves, meaning the first person character I'm just going to plug this in. So let's understand what we're doing here. We're saying on Event Begin Play. We are going to set our respond transform that exists within our BP game mode gameplay to our actor, first person characters transform location, so the location and rotation of our character When they spawn in, that is what we want to set our respond transform to be, that's going to be real handy because no matter where we have our players start located in the level. That is where we are basically saying we want our BP game mode gameplay respond transform variable to be.

Okay, so with that bit of script, I'm going to left click, drag out, tap that C key and say sets character character, respawn, sets with the apostrophe, I don't need an apostrophe there, sets character respawn transform in our game mode. Gameplay and we're gonna Compile and Save that right away. Next, we're going to come under this area of the My Blueprint panel in your friend Person character Click Next to this little eyeball icon here. And we want to show inherited variables. When we do that, come down to this area at the very bottom known as event dispatchers in under your game event dispatchers under damaged, expand that out as well. You are going to find an on Well actually we don't need to expand that damaged out.

Right here's the one we are looking for. There is an Event Dispatcher on our First Person character known as ondestroy. Now what is this? We haven't talked about event dispatchers yet basically event dispatchers are way to communicate from one blueprint to another. Now you're all familiar with Twitter and how that works. Basically an Event Dispatcher as I've heard it explained by Zack Parrish from Epic Games, he said it's a lot like Twitter.

And I agree, great comparison. Essentially, when our First Person character dies, they can send out a quote unquote tweet, aka, dispatch an event to inform another blueprint that they have been destroyed. In this case they have died. Now we want to commute this information ultimately, over into our BP game mode gameplay. And in order for our BP game mode gameplay to understand that that has happened. This BP game mode gameplay needs to quote unquote subscribe to that tweet, that first person character is sending out and we'll get to that in just a moment.

But I wanted to point out here that there are some event dispatchers aka tweets that a first person character can send out and these are currently here by default. We did not have to do anything to create these event dispatchers. Okay, so with that understood, let's jump on over to our BP demo gameplay. Now we've been doing a lot of stuff off of our Event Begin Play in our sequence node right here, I'm going to add yet a nother pin. And let's bring this down a little bit further so we can keep this all in view. And what I'm going to do is I'm going to right click in some empty space and I'm going to say Get Player Character.

Then out of this, I am going to cast to our First Person character so we can talk to our First Person character, hook this in off of the then for output. Okay, and then what we want to do is drag a wire out of our First Person character and I'm going to do a search for a sign On these stroyed this is one you are looking for right here it says a sign on destroyed. If we click on this, it's going to bring in two nodes, there is this bind event node, as well as a custom event that already has a name. We can leave that name by default, but essentially what we are saying here, and I must hook in this execution wire as well, is that upon beginning play, we are going to subscribe to this on destroyed event that exists within our First Person character.

So that when our First Person character is destroyed, aka they die, then this event will fire off. Now note that without this binding right here, to this custom event, none of this can happen. There's no way for our game mode gameplay to understand that our First Person character has died. Okay, so next what we want to do is off of this on destroy event zero, I'm going to drag out a wire and I'm going to add a short delay, because before we respond them we want to have a little bit of a delay. So they don't just respond immediately the user actually has a moment to understand that they have died, right. So I'm gonna set that to be two seconds.

Okay, then down below. I'm going to bring in our respond transform, we're going to get that and the reason I'm gonna get that is because off of this delay node, I'm going to drag off a wire and say spawn actor from class. Which actor do we want to spawn after we have died? Well, we want to spawn our First Person character, so I'm going to type in First Person. Now note that I've got two of them here, there's two options. We want this first one with the character type icon.

And then of course, we got us specify where is the spawn transform, like where do we want to spawn them in. That's where our respond transform comes in. Okay, next what we want to do is right click, and we're going to do something called Getting a Player Controller. Now the Player Controller is this thing that exists as a framework blueprint. We are going to be dealing with it a little bit later actually, but it is the blueprint that determines us controlling having some control over our pawn. And the reason we are going to get this is because off of this I want to drag out a wire and say possess I want to possess a pawn.

So after our First Person character has been spawned after dying, I want to possess a new pawn which spawn our First Person character so we can take out this spawned actor is spawn first person character, and that is the spawn that we want to control. Lastly, let's just add a sound effect in here. So I'm going to drag out a where do you play sound 2d, and we will slot in the sound How about start, simulate, start simulate cue. Alright, with all that done. Let's just add a comment block around all this bit of script and actually, let me frame it up here so you can see what we have all done. And I will tap that C key And we will call this respond player.

Once more I'm going to Compile and Save. Let's just jump in and play now and see if this works. Now I am currently on my level oh one, I have switched off of my start menu. So if I click Play directly from here, I'm not going to go through my Start Menu I'm simply going to play immediately from the start of my level. So let me just go through this door and I've got some work to do with my lighting. And I'm just going to let this fan kill me 12345 I am dead one, two seconds.

There we are right back in but you will notice that there's currently a problem. I'm gonna kill myself one more time. 12345120 no respond. What happened? Well, there is more work to be done. Jumping back into our BEP game mode gameplay, what is currently going on here is upon beginning play, we're casting to our First Person character and out of that, we are subscribing to our on destroyed event for when our First Person character dies.

That's what this does. And once our character dies, this event is triggered. We then wait two seconds, respond our First Person character are giving control over him possessive and that sound plays. So that happens one time. But what happens if we were to die again? Well, essentially, we need to re subscribe to this on destroyed so this is going to be pretty simple to do.

If we come right back towards the beginning of this particular script, we could right click and create a custom event. So just right click type in custom event. We will call this respond. plug this in like so. And now we created this custom event, but there's nothing calling it. So what we're going to do is come to the very end of our response script here after our play sound 2d.

And now because we have created that Custom Event, I can drag off of a wire in type in respawn, and there is the call function for respawn. That is going to call for this custom event to then go off and re subscribe to that on destroyed events so that this can fire off again. So it doesn't matter how many times we die, at the very end of us dying and being respond. This will link back to here. Cool I actually could have skipped this whole Custom Event thing and drag this wire all the way from here back into here but I don't like to have lines criss crossing. Don't criss cross the wires.

So now let's try this one more time Compile and Save. Let's play. I'm going to open that Let's die. Okay died. respond. Let's try this one more time died respond and you'll notice my time is not resetting either which is what I want it continues to tick down.

Let's try dying a third time died and respond time is continuing to tick down as well. So that is working is intended guys that is gonna do it off. For this one, we now have a response system in place. let's just recap one more time exactly how this is all working because I understand this can be a little confusing. So here in our game mode gameplay, we did create a respond transform variable. We created it to live in our game mode gameplay, but we are not setting the location and the rotation here instead, in our First Person character.

Upon beginning play upon the very beginning of our game, we are setting our spawn transformed to be the exact location where our First Person character spawns in. That's pretty cool. Then jumping back to our BP game mode gameplay. We are saying that upon beginning play, we're going to ask our First Person character, we would like to subscribe To his on destroyed tweets, that Event Dispatcher again. And our First Person character here is an Event Dispatcher that lives here automatically called on destroyed that will happen we'll send out a tweet when whenever our character dies. So once our character does die, this event will fire off we'll wait two seconds, we will spawn a new first person character at that respond transformation.

And then we will be able to possess it. We play a sound and then we say trigger that respond Custom Event right here. So that we can subscribe to any more on destroyed tweets, event dispatchers that happen again. Guys, that is gonna do it all for this one. We'll see when the next one

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.