Open level and change player start location

I’m working on a blueprint for component to be added to the doors in my game. Part of the functionality of the component is that when you click on a door, it takes you from one level to another. Levels, of course, can have more than one door, and each door should have a corresponding player start to make it appear as though you exited the appropriate door.

i’ve been struggling getting the engine to change the player start to be used upon opening a level.

So, each door has a DestinationDoor variable and a PlayerStart variable. What I’m trying to do is get the DestinationDoor of the door you interact with in order to get that door’s PlayerStart variable, then set that as a variable inside of the ChoosePlayerStart function inside of my GameMode BP.

It’s not working. Instead of using the referenced player start, it just drops me at 0,0,0 (even when I choose “Play from this location” in the editor).

After running PIE, I get the following error message:

Blueprint Runtime Error: “Accessed None trying to read property CallFunc_GetActorOfClass_ReturnValue”. Node: Set PlayerStart (GameMode) Graph: EventGraph Function: Execute Ubergraph Door System Component Blueprint: DoorSystemComponent

So, what gives? How else can I pass this variable to the GameMode BP? Unfortunately, you can’t set a PlayerStart object reference variable in a BP, you have to do it on the instance in the world, and you can only select instances in the current level.

I thought about maybe trying to do all of this inside of the ChoosePlayerStart function, but I’m not sure how I’d go about getting all of the variables I need in there. Any thoughts?

I think there are some flaws in your code.

First of all the GameMode gets destroyed and a new instance is instantiated when you call “Open Level”. So, whatever you set on it before loading the new map will be reset. Instead you should either use GameInstance to store your target location or, how I would try it, pass it as a Parameter of the open level node. Check Open Level Options - #13 by Atheist91.

Second, since your destination door doesn’t exist in the current level “Get actors of class” can not find it, resulting in your runtime error.

Third, your “Destination Door” variable is a class type reference. Doing it like that would mean for each destination door you would have to create a dedicated class. So for 100 doors you would have to create 100 classes. Not optimal. Instead I propose to use actor tags instead. So each destination playerstart would get a unique actor tag.

So in the end, I would pass the destinations actor tag as a parameter to the open level node. Then in your GameMode inside of “ChoosePlayerStart” you can use the “Get All actors of class with Tag” to find a player start having the passed over Tag.

Hope that makes sense to you.

But I need to pass it over before I open the new level, right? But the GameMode gets destroyed when I open the level? So will the tag perdure?

That’s why you pass the tag as options in the open level node, not as a variable of GameMode. As the options gets passed over to the new GameMode insurance.

So I pass a string into the Options input pin called “?PlayerStartTag=####” where #### is the tag of the player start that corresponds to the destination door of the door actor being interacted with?

Yes, that’s what I’d try.