Game Instance does not store Variable - Accessed None

Hello Community,

looks like i just ran into a problem that 's so simple, nobody ever had it before.

Its about storing a simple integer in a custom Game Instance for transfering it to another level.

I did the following Steps:

  1. Make a new blueprint from class game instance, called MyGameInstance

  2. Set in Project Setting, Maps and modes, the Game instance to MyGameInstance

  1. Making a new Variable within MyGameInstance called x, integer, “open the eye”, editable.
  2. In Player charakter, ( side scroller in my example from side Scroller example project) making a variable y, integer.
  3. On begin play, get game instance and cast it to MyGameInstance, print string to see if cast was successfull.

  1. Promote the Cast output to Variable, called My Game Instance
  2. On Event Z, set y by adding “1” to it and print y as string.
  3. Get the MyGameInstacne reference, get X from MyGameInstance, add 1 to it, and set X from MyGameInstance to the new value. ( I first tried to put in y directly into x, but in that tutorial, they did it that way: Blueprint Game Framework Basics | Live Training | Unreal Engine - YouTube)
  4. Print x as string

in this Screenshot, i tried again to get Y directly into X, but outcome is still the same.

Also having a basic open level node, on event K, to change levels in both of the level blueprints, pointing to the other level.

So, when i start the game in editor (also tried stand alone), i get the string that everything worked well on the casting. but wenn i hit Z, which incerements X and Y, and printing a string of both, i see that it works on Y ( the variable within the character) but not on X ( variable in MyGameInstance). Of course, after changing a level, its counting again from zero, while x still stays zero. and the accessed none of property error also occures while playing.

the funny thing is i think i make everything like they tell us in the tutorials and documentation, but somehow i can’t get it to work. Looks like im missing something so obvioous, nobody ever ran into that problem. I must confess, im not an programmer, and have only a little understaning of scripting.

Would be kind if somebody tells me what i am doing wrong.

Got the first part of the problem. I need to get the output of the casting directly into the set X , so both variables will raise. but on changing level, the charakter on begin play casts a new mygameinstance, and starts counting from zero. maybe character is a bad place to cast that? because on every level there is a new begin play event=> new cast=> empty variable at game isntance again? but also occures if i not use the begin play event. on event O for example, i get accessed none again, untill i hit O, then its working fine, but on change level, i need do cast it again with “pressing O”, but it still starts at zero. any ideas?

In your character.jpg you are setting a variable x from you mygameinstance to the Y value.

It looks like you were trying to get the X value of mygameinstance and add 1 to it, but you didn’t drag off of that addition to set the new value for X in mygameinstance?

You could try and use a game state instead of game instance. I think game state stays the same when changing levels. Look up game state, also check out game mode. They both can be easily accessed but are differnt when changing levels. I think… Google it, heh.

Im a n0ob myself.

Good Luck!
~

i solved it. when i promote it to a variable, i need to set it too. that worked. and i need the second increment part for the x, because if i set x=y, it always will start at 0 because y is always set back to default when beginning the new level. very… “smart” by me.thank you anyway for your comment.