Download

Pass score to new levels

Hello, pretty new to Unreal from Unity (hooray!).

I’m not sure the best way to handle this but here’s my goal and what I’m doing.

Game opens to main level where user interacts. Upon interaction and game over, I am loading a new level (Fail Screen). I just use BP to OpenLevel which loads my next setup.

In each Level (Start and Fail) I use the Level Blueprints to handle the game logic and displaying the text I want.

How would I then pass the scores from the Start Level BP to the Fail Level BP? After that I would save them to a slot when they return to the game next time. Similar to PlayerPrefs in Unity.

Thank you!

You can either save them in SaveGame’s (Google/Youtube, there are plenty of tutorials) or you use the GameInstance class. You can create your own BP version of it
and set it in the Maps and Nodes settings in your Project Settings. This class survives Level changes.

What you want is to store the player score in something that is not volatile like the level. The score should be stored in the **Playerstate **or the **GameState **which you can set under Project Settings / Maps & Mode / Selected **GameMode **(create a new ones via +, etc.)

From your player controller you can do a get **GameState **and then cast to “your gamestate class” and set the score there. The fail level will be able to grab it.

@keyle: He is loading a complete new Level and wants to pass the data over from the first to the second. GameState, PlayerState etc will all be killed and newly spawned, so this is not an option.
The only way to use this is to use the buggy seamless travel and set them as actor that should survive the level change. Or he uses the things i posted above.

Correct me if i’m wrong.

Another option is to pass values as URL parameters. For example when you open a level or connect to a server using the “open MyLevel” or “open 127.0.0.1” console command you can add parameters like this: “open MyLevel?name=Peter?spawnpoint=5”. The tokens, separated by the ?, are passed to the new level’s game mode in the Event Login as the Options string array.

I would call this pure gold, but is this actually working in Blueprints only? The Login Event is not exposed, but there seems to be an “Option String” Variable.
Can it be used for this?