Making a respawn for my vehicle?

Hey guys I’m new to unreal 4 and just going to say, it’s really awesome and cool! ^^ So I have this college assignment to make a playable 3D game with some interaction, so I decided to do a time attack racing game, everything is going great; using the car blueprint project and managed to get car AI working thanks to a tutorial online. But I have one little thing I want to add in my game but I can’t find any tutorials so I decided to post this to you guys to see if you could help me out with this. :3

I basically want to make it so if my car crashes and falls on it’s side/upside-down I could simply press a binded key to make it respawn at the same place it tipped over.

Thanks ^^

Hi Korey, and welcome to UE4! Have you checked out How to Respawn a Player in Blueprints from the documentation?

Ahh thank you!! How didn’t I see this before xD

Okay new problem, I followed the guide and it doesn’t work for me sadly, when I start the game and press R it just destroys my car and nothing happens after that… Here’s a few screenshots

When you cast to the sedan in the GameMode, the object reference should be the character, not the controller. Basically, you are binding the OnDestroyed event to the Sedan, but are telling the controller to respawn, not the Sedan itself. Try changing that, and let me know if that fixes it.


Well I can’t find “MyCharacter” or any character to be exact :S
Sorry about this, I’m still new to all this.

LOL sorry about that, I just posted the example from the documentation. What I was trying to hint at was in your Game Mode (i.e. MyGame), from the “Cast To Sedan” node, change the “Object” pin connection from “Get Player Controller” to “Get Player Character”. The easiest way to do this, is to just select and delete the “Get Player Controller” node, then drag off the “Object” pin and type “Get Player Character”. I’m not at home, and don’t have access to UE4 right now, but can upload a more accurate image if necessary.

Okay I just swapped the get player controller to get player character then I tested it, still nothing :confused:

AHA! Just had a light bulb moment :slight_smile:

So… this gets a little tricksy. Since you are dealing with the Sedan BP as your Player Pawn (not a character based class, but pawn based), you need to cast to it’s parent first to be able to talk to it directly. If you look up to the top-right corner of your Sedan BP, you will notice it says “Parent class: Wheeled Vehicle”. This means that it not only is the Sedan, but it is derived from the Wheeled Vehicle class as well (which gives it physics and such). In order to go from the Game Mode to the Sedan, we need to get the pawn, cast it to the Wheeled Vehicle class, then recast to the Sedan.

Also, something fun to play around with during casting, is the “Cast Failed” pin. This lets us do something else if the cast ever fails on us. I added a “Print String” node, and typed in some information to see how far the casting was actually getting for quick & dirty debugging (there are much more elegant ways to debug, I’m just not there yet LOL).

The only issue I’ve run into so far, is that whenever I make it respawn the car, it will only do it completely one time. I’m not 100% sure why this is the case, but don’t have much time to really look into it now, sorry. If you need further help though, I am willing to help and learn when/where I can. :slight_smile:

Aha! It works thank you ^^ And mine keeps repeating so that’s a plus :smiley:

So I have another question related to this, instead of respawning to the PlayerStart location is it possible to make something that whenever I hit respawn, it will take me to the closest place to respawn on the track instead of taking me all the way back to the start of the track, because as you see I’m making a time attack-ish game and my sedan tends to tip over abit if you’re not careful.

Sorry for the late response. I’ve been out of town in Federated Identity Management training, ugh! :slight_smile:

Yes, it most certainly is! You have a several ways to accomplish this. Just to name a few, you could make the vehicle respawn…

  • in it’s current position,
  • in a set position,
  • or at the location of another object.

Here’s how you would make it respawn in-place (same facing, orientation, etc.)…

In short, what we’ve done is told the Sedan BP that when we press the F key, we are going to tell the Game Mode to set the Spawn Transform (where we get spawned) to the Actor’s current Transform prior to it being destroyed. Then we destroy the actor, and the Game Mode respawns the pawn in the new set Transform.

Something to consider: if you are going to have your actor flip over/run off-road/sink in a lake/etc., you probably won’t want to use this method specifically. However, this is a very basic idea, and should get you moving in the right direction. Use this as your base, and figure out what it is you need to accomplish to make the actor spawn somewhere other than it’s current location (location of something else), as well as to set it’s orientation on spawn (upright, facing the correct direction, etc.).

Thanks man you’re awesome, I’ll try this whenever I have time to use my computer and I’ll let you know if it works ^^

Okay it works, but now I want to know how to change it’s position to make the vehicle stand up again like you said being able to face the right direction on the track when it spawns.

One word to point you in the right direction: rotation. :slight_smile: (pun completely intended)

I know you’re trying to help me by pointing me in the right direction to figure this out myself, but this is really confusing for me…

You could say it’s “unreal” :stuck_out_tongue:

LOL that it is! I’m in the same exact boat as you are when it comes to this kind of stuff. There doesn’t seem to be enough real information out there for us beginners to transition from beginner to intermediate (not that Unreal Engine 4 is really that old, or I am any good at it! LOL). Anyway, here’s my suggestion:

In the Unreal launcher, select the Learn tab, then scroll down to the Example Game Projects section. There, you will find a Vehicle Game project (I just found it myself a few days ago). Download it and check it out. Inside of the VH_Buggy Blueprint, there is a section sequenced off of the Event Tick that should help with determining if the vehicle is stuck (instead of forcing the user to press a button to respawn, but I’d keep the button for the development cycle so you can at least test the functionality easier).

Most of the real meat of the project is done in C++, but what it looks like to me is that they have created CheckPoint actors with an arrow facing the correct direction on the track. Whenever the buggy overlaps the actor, it records that CheckPoint as the last one it touched. If the buggy gets stuck, it is destroyed and respawns at the last known CheckPoint actor, facing the same direction as that actor. You can accomplish all of this in Blueprints. What I don’t know for certain is whether you will have to cast to the level Blueprint from the GameMode to get that CheckPoint reference, or if you’ll need to handle respawning in the level Blueprint instead.

i have started making a vehicle advanced game and wondering how i would finish the event