How do I keep an array of variables from one level to the next?

A custom GameInstance is the right way to go. Everything except your GameInstance will be wiped when opening a new level, so any variables you store in there should carry over. I suspect the issue has nothing to do with arrays but rather your implementation.

Start with a simple proof of concept to make sure everything is working.

  1. Create a new BluePrint that inherits from GameInstance, call it “MyGameInstance” or something.
  2. Create a variable in there, a String variable called “TestVar” for example. Leave the default value to be empty string.
  3. Create 2 maps.
  4. In the first map, go to the Level Blueprint and on the Event BeginPlay make a “Get Game Instance” node, cast it to your MyGameInstance, then from the instance draw out a node and call “Set TestVar”. Type in a string there, say “Hello World” or something.
  5. Do whatever it is you’re doing to Open Level your 2nd map. Either a key press or whatever it is that you’re using as your trigger.
  6. In your 2nd map, open the Level Blueprint and again on Event BeginPlay just draw out a node for Get Game Instance, cast it to your MyGameInstance, and then from the instance draw out a node to Get TestVar. Then connect that to a Print and see what it says.
  7. Run it. It should show some debug print text saying “Hello World”.

If that doesn’t work, it’s probably because you forgot to set your Instance class in your Project Settings. Go to Edit → Project Settings → Maps & Modes. The very bottom option lets you select your custom Game Instance blueprint.

Hope that helps.

O

Im using a game instance blueprint to store variables and move them to another level, but it doesnt work with arrays, the array just gets cleared after the map loads. Is this normal? how can I store an array of variables that doesnt get lost between levels?

I got it to work now. The reason I thought the arrays were the issue is because I got it to work correctly with other variables already. I did exactly the same with the array as with the other variables, but apparently I cant just “set” an array with the same value as other array (as you do with non array variables) because it seems that was the problem, when I instead cleared the array and used a “for each loop” node to transfer each item from one array to the other it worked correctly

Excellent description of how to use a game instance. Thank you.