Game Instance?

I am trying to create a game instance to keep a picked up item on the character when changing levels. I have a blueprint setup for the item, but want to know how to set it so that when other levels load the player still has the item in their hand. I have been looking all over online how to do it, but can only find tutorials on variables rather than equipment.

1 Like

If you’re using the game mode in each level to spawn the character ( the default ), then your character will need to check the game instance as every level starts, and redo the pickup ( respawn the item in their hand ).

If you use level streaming, the character spawns in the persistent level and will not change as you unload / load the other levels.

The first is probably easier if you’re not used to streaming.

Thanks for getting back, how do I code the game mode to check that I have the picked up the Item?

1 Like

You don’t do anything to the game mode.

You code the player ( which gets created at the start of every level ), to check the level instance to see what pickups it has, and re-pick them up :slight_smile:

Right okay. So do I just get the game mode from the begin play event in the player blueprint.

1 Like

Nope :slight_smile:

Forget I mentioned the game mode.

In your player, on begin play, you get the game instance, and read what pickup you got before you changed levels.

You then re-run that bit of code in the player, the bit where they picked up something. So they are still holding it now, in the new level.

I only talked about the game mode, because that’s what makes your player appear in every level.

Right I understand. Do I need to add anything to my item Blueprint first? I have added a screen of my irem blueprint if it helps.

1 Like

Yes you do :slight_smile:

The item has to store something in a variable in the GI so that the player knows the pickup has happened. Otherwise how do you know in the next level?

What you put in the GI is up to you and depends on how many different sorts of things the player can pick up.

Let’s make it very simple to start with, just a bool. So the pickup sets the bool in the GI before it destroys itself. In the new level, the player reads the GI, sees the bool is true, and puts the pickup in their hand again.

Like that.

Right. I’ll create a boolean called Picked up. Then call it in the player Blueprint and after the events to open a new level and should that do it?

In the player, on begin play. Because when you change levels, you get a new player :slight_smile:

Cool, I’ll do that now. Speaking of which in the game instance, how do I reference the variable from the item blueprint?

Like this, in the pickup

Then in the player

Okay, so I don’t have to add anything in the Game instance Blueprint? Only the Item and the Player.

1 Like

Right. Except you have to put the variable in the GI, of course…

Cool. On your screenshot, where it says other Actor on the begin overlap event, I am using my own interact interface, how do I add that output to my interface.

Yes, just do that bit with your interface call. So

Interface call → store variable → destroy actor

Okay I have created the function on my interface and have set up the first part of the code. On the boolean variable to indicate the player has picked up the item, how do I add an actor function to it? I can’t find the option to add an actor pin to it?

Forget my initial repl, I just realised I’ve been trying to create the variable for pick up in the item Blueprint lol. I have just created in the instance now.

1 Like

Does it work yet?



Are the Blueprints in the screenshots above correct?

Also, on the character Blueprint, what do I need to add after the cast to Game instance and the branch? In the screen you provided it said I need the Pick up code. Is the code, the one in my screenshots below?