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
€93.07
List Price:  €130.30
You save:  €37.23
£79.62
List Price:  £111.47
You save:  £31.85
CA$136.60
List Price:  CA$191.24
You save:  CA$54.64
A$151.87
List Price:  A$212.63
You save:  A$60.75
S$135.20
List Price:  S$189.29
You save:  S$54.08
HK$781.33
List Price:  HK$1,093.90
You save:  HK$312.56
CHF 90.72
List Price:  CHF 127.01
You save:  CHF 36.29
NOK kr1,092.46
List Price:  NOK kr1,529.50
You save:  NOK kr437.03
DKK kr694.20
List Price:  DKK kr971.90
You save:  DKK kr277.70
NZ$167.15
List Price:  NZ$234.02
You save:  NZ$66.86
د.إ367.25
List Price:  د.إ514.16
You save:  د.إ146.91
৳10,946.16
List Price:  ৳15,325.07
You save:  ৳4,378.90
₹8,342.71
List Price:  ₹11,680.13
You save:  ₹3,337.42
RM473.95
List Price:  RM663.55
You save:  RM189.60
₦123,487.65
List Price:  ₦172,887.65
You save:  ₦49,400
₨27,847.21
List Price:  ₨38,987.21
You save:  ₨11,140
฿3,679.53
List Price:  ฿5,151.49
You save:  ฿1,471.96
₺3,232.18
List Price:  ₺4,525.18
You save:  ₺1,293
B$511.10
List Price:  B$715.57
You save:  B$204.46
R1,851.52
List Price:  R2,592.21
You save:  R740.68
Лв181.98
List Price:  Лв254.78
You save:  Лв72.80
₩135,881.87
List Price:  ₩190,240.05
You save:  ₩54,358.18
₪371.60
List Price:  ₪520.25
You save:  ₪148.65
₱5,713.97
List Price:  ₱7,999.79
You save:  ₱2,285.82
¥15,308.41
List Price:  ¥21,432.39
You save:  ¥6,123.98
MX$1,693.57
List Price:  MX$2,371.07
You save:  MX$677.49
QR364.01
List Price:  QR509.63
You save:  QR145.62
P1,365.33
List Price:  P1,911.52
You save:  P546.18
KSh13,468.65
List Price:  KSh18,856.65
You save:  KSh5,388
E£4,794.02
List Price:  E£6,711.82
You save:  E£1,917.80
ብር5,699.43
List Price:  ብር7,979.43
You save:  ብር2,280
Kz83,741.62
List Price:  Kz117,241.62
You save:  Kz33,500
CLP$94,755.52
List Price:  CLP$132,661.52
You save:  CLP$37,906
CN¥723.62
List Price:  CN¥1,013.10
You save:  CN¥289.48
RD$5,785.38
List Price:  RD$8,099.76
You save:  RD$2,314.38
DA13,457.99
List Price:  DA18,841.73
You save:  DA5,383.73
FJ$225.30
List Price:  FJ$315.43
You save:  FJ$90.13
Q775.21
List Price:  Q1,085.33
You save:  Q310.11
GY$20,876.73
List Price:  GY$29,228.26
You save:  GY$8,351.52
ISK kr13,989.60
List Price:  ISK kr19,586
You save:  ISK kr5,596.40
DH1,008.69
List Price:  DH1,412.20
You save:  DH403.51
L1,771.31
List Price:  L2,479.90
You save:  L708.59
ден5,730.13
List Price:  ден8,022.42
You save:  ден2,292.28
MOP$803.11
List Price:  MOP$1,124.38
You save:  MOP$321.27
N$1,860.85
List Price:  N$2,605.27
You save:  N$744.41
C$3,673.63
List Price:  C$5,143.23
You save:  C$1,469.60
रु13,311.40
List Price:  रु18,636.50
You save:  रु5,325.09
S/375.46
List Price:  S/525.66
You save:  S/150.20
K383.63
List Price:  K537.10
You save:  K153.47
SAR375.03
List Price:  SAR525.05
You save:  SAR150.02
ZK2,685.42
List Price:  ZK3,759.69
You save:  ZK1,074.27
L463.14
List Price:  L648.42
You save:  L185.27
Kč2,328.17
List Price:  Kč3,259.54
You save:  Kč931.36
Ft36,248.95
List Price:  Ft50,749.98
You save:  Ft14,501.03
SEK kr1,083.98
List Price:  SEK kr1,517.62
You save:  SEK kr433.63
ARS$87,816.53
List Price:  ARS$122,946.66
You save:  ARS$35,130.12
Bs689.12
List Price:  Bs964.79
You save:  Bs275.67
COP$389,940.87
List Price:  COP$545,932.82
You save:  COP$155,991.94
₡50,893.45
List Price:  ₡71,252.86
You save:  ₡20,359.41
L2,475.75
List Price:  L3,466.15
You save:  L990.40
₲747,391.81
List Price:  ₲1,046,378.43
You save:  ₲298,986.62
$U3,833.15
List Price:  $U5,366.56
You save:  $U1,533.41
zł402.67
List Price:  zł563.75
You save:  zł161.08
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.