How to use the GameInstance BP to send info to other levels?

I’m starting to get in to the multilevel part of development, and I’m not sure how this GameInstance BP works. I know you put it in the Maps & Modes Project settings.

I found how to load another level in the game, but I want to send my variable settings from one level to the next.

For example:

In Level 1 = Player select, so you choose your character and that will set a variable.

Other level loads, and can tell which character you chose

How do you make that work?

I just need a simple example, like setting an integer value in one level, and reading it in the next with Print String in the level BP.

Thanks

It’s easy. You just need to set a variable in your GameInstance Blueprint. Just open your GameInstance BP, create a variable and made it editable.

When you want to get or set a value for that variable (in level BP, pawn BP or whatever place you want) you just call “Get Game Instance” in Event Graph or Construction Script and make a “Cast to WhateverNameOfYourGameInstance”. From there, you can just call Get/Set functions for every variable you have set on GameInstance.

I have a pretty easy example. In my game, I ask for the name of the player just before playing:

Then, when level loads and character is created, on construction script I use the following to put the name on the pawn class:

All of this is pretty basic (I just learned how to use it a few hours ago), but I’m sure you’ll get everything right from here :slight_smile:

Hope this helps you!

Awesome, thanks for the example!

sounds good… but
where do you put your game_instance instance? one instance in each map???
or where?

EDIT: don’t worry, I got it now, it’s set in project settings under “games and modes” section.
Now if we have this handy GameInstance thing, who needs GameMode??

It is explained here