Spawning Player as a Pawn Chosen in Another Level's Menu

I’m going mad over what should be a simple and straightforward thing that just isn’t working.

I’m making a car game and the menu for choosing which car you want to drive is a widget blueprint in a level (setting of a car dealership) Choose car from the menu, it shows that car, that works fine. Hit play, it takes you to the level where you drive.

Getting it so the player starts as the car they chose, that’s either half working or not working at all. I can get it to spawn as the car you selected and drive it in the game mode

But it places you at the level origin and not the player start. If you look closely it’s pointing to a target point, not the player start because oddly, when using the player start, I’m spawned in the level without the car or any control at the origin, but if I use the target point, you start in the appropriate car and have control, but are at the origin. For reference the player start and target point are right next to each other.

Or I can get the player to start the level at the player spawn, but as the default pawn, just floating around.

Hey @EraserTR!

So for some tests:

Firstly, put a printString on your “Cast Failed” Exec off of Cast To MyGameInstance. That way we can rule that out.

Secondly, your “Get Actor Of Class” node isn’t doing anything? Is it supposed to be doing something?

Thirdly, Try putting a printString in between “Get Actor Of Class” and “SpawnActor”, and plug in your “SpawnLocation.” That way when you spawn the car it should print your location- if it’s returning 0, that’s the thread to follow, if it’s returning a location but spawning at origin still then we have to look elsewhere, hopefully we won’t have to.

Give that stuff a try and let us know!

That get Actor of Class node was left over from trying to get it to work another way. First I was trying to access the location of the player start and then target point directly in the game mode. Thinking that wasn’t communicating, I made a transform variable stored in the game instance and the level blueprint sends the position to that variable. That resulted in showing up at the player start, but without a car.

I tried adding print statements for casting failures like you suggested and didn’t get any. Nor did I get one for trying to print out the location.

However I did manage to spot this in the log “PIE: Error: Blueprint Runtime Error: “Accessed None trying to read property CallFunc_GetActorOfClass_ReturnValue”. Node: Set SpawnLocation Graph: EventGraph Function: Execute Ubergraph Washington Square Export Blueprint: Washington_Square_export”

And that graph in the level BP is

Don’t know if i can help, but i have this on my level bp:

I am awso choosing which player to spawn in the main menu and then the level bp spawns him at the location set. Maybe you should awso try to spawn the player/car directly on the level BP and not on the game mode BP..

I originally did it exactly like that in the level blueprint and spawned in the right location but without a car.

1 Like

So now you don’t get any print strings to the spawn location but the car spawns ? Maybe you can try to dispatch the location instead with a dispatcher.

But not sure whats going on i may need to reread your post..

Edit: Maybe the game instance is loading first then the level BP. If you send the location from the level BP it is awready spawning your car and then the level BP sends the stored location variable. So the game instance have no information to the location. Or the other way around. I would spawn the car and location both in the same BP then.. And if it don’t get print strings in the game mode/instance then try again on level BP and do both location and car spawning with print strings there and see what happens.

THAT is likely it!

Because the Get Actor of class is returning Nothing, it can’t get the location, and set that as the spawn location variable, used in the later graph.

This is likely a load order issue. It’s searching for the TargetPoint object before it has spawned, returning nothing. So here’s what to do:

After “GetActorOfClass” use an “IsValid?” Macro (Make sure it’s the gray macro) to check that return value. Then if it IS valid, set the spawn location. If it IS NOT valid, run to a delay node for idk let’s say .01 value, and out of the delay node plug BACK INTO “Get Actor Of Class”.

This will create a loop that will not finish or return an error until a Target Point Actor is FOUND. :slight_smile:

1 Like

Okay so I tried to do that, and it still spawned at the origin

Can you show a picture of what you got down for the code? If this isn’t working it should be throwing an error giving you a thread to follow… Or you’re telling it to spawn even if the spawn location is invalid. You will probably need to add a valid check to the spawn code as well.

I tried to set it up exactly as you said

Ok. So this is confirming that it IS finding the target point.

Wait. The Target Point could be in the wrong location when the Location gets pulled. I didn’t think it would be placed within the level.

Maybe use a printstring to print the actor transform of the Target Point. Maybe put one on the target point actor itself printing it’s location, then one here before SpawnActor?

Ok I put a print statement between the Is Valid node and setting the transform variable and it does print out coordinates.

I tried switching the spawn logic from the gamemode BP to the level BP to see if that would help with the order of things and communicating the locations/variables. Weirdly though it spawns the car at the origin still but no longer possess it, or doesn’t spawn a car at all and has the camera at origin and no control and there seems to be no rhyme or reason to it. Yet putting it back in the Gamemode it spawns and gives you control fine, just in the wrong spot.

Where do you have the Target Point location being changed?

It may be good to have that location being set on CONSTRUCTION script if it’s being set on beginplay or something. That would put it a good bit earlier. Also wherever you have the code to move the target point, you could then call an event to spawn and possess the car ( instead of it being on begin play use a Custom Event).

How? From what I understand UE5 doesn’t do a construction graph for level blueprints, so it’s been going off of Event BeginPlay.

It doesn’t- you want to limit using the Level Blueprint as much as possible, however- mainly because you can’t cast to the LBP. I’m actually questioning here- what’s the TargetPoint blueprint for?

I guess what needs to be done here is you need to ensure the order of operations. This is part of the reason for a loading screen- it just hides the loading from the player, behind that screen is the level loading up. Let’s work this out without the Target Point. All the target point does (as far as I’m aware ) is BE a location. That can just be pulled from the GameInstance, like you’re doing above.

What is the reason for the shifting of Spawn Location? Is it extremely changeable?

Try doing a 3 second delay before the spawn, and under any spawn location, put a plane for the car to sit on that could guarantee a spot for it to be while the rest of the level loads?

The target point was an alternative to the Player Start, which wasn’t working when I was just trying to access the player start. In the game mode, I initially tried to spawn the car at the player start and I was getting nothing and no player control.

But in the game mode blueprint if I got a target point instead of the player start, I was actually spawning with control at the origin, like so.

Well let’s just stick with using player start and understanding why that isn’t working. Did you make sure to possess it and everything when spawning at the Player Start? It won’t automatically work if you’re switching things up from the default of the GameMode, negating auto-possess you have to do it manually.

I don’t know if you know that player starts can have a tag and that there is a function that searches for them.

Yes, I am possessing it manually because I’m doing half of this in a custom game mode.

I went and refined the print strings even more. The blue is printing the transform of the player start. Yellow is doing the same, after it has set the variable SpawnLocation and they’re the same.

Then it prints the name of the actor in blue again, and lastly the value from SpawnLocation again in orange. It’s the orange one that comes back as 0,0

Also the order does not seem to match.

Ignore the Traffic warnings, that’s because one way roads’ last segment don’t have anything assigned as a next segment and the traffic just destroys.

Yeah, I can see how this might be confusing, but it reads bottom to top, not top to bottom. So the order is:

  1. Name
  2. Orange
  3. Blue
  4. Yellow

So it is going in the right order. It’s blank(orange) then gets set using the player start(blue) then reprints (yellow). That part IS working correctly!