Game instance doesn't maintain some variables after map change

Hey guys,
I’ve run into a problem with the game instance trying to pass variables across maps. I set the instances copy of the variables using a two part method:

First a group of the variables are set, with some being left as defaults for now.

Then I set the variables right before the map changes and I print the values that the instance now has.


(The prints occur offscreen but I just get the game instance, cast to the specific type, and then get the variables that I want and print the display names)

Then the map changes

Then the player character gets the values and prints them.

Now when the player character prints the variables after the map change some are not the same as the ones that are printed immediately before, instead being the default ones that were mentioned earlier. I don’t know where to go from here, so as always if anybody can enlighten me as to what I’ve done wrong it would be greatly appreciated.

UPDATE:
The problem appears to have something to do with the blueprint not setting the instance values correctly because I printed it in multiple other locations in the original map and the problem is still the same. I replaced the yellow print to print the same thing across all 6 of the objects that perform the task and only one of them printed the answer I needed meaning that the problem must lie somewhere in the way it is being set and/or printed.
The variable is being set in a way that means that when it is called by the blueprint that sets it it will return the updated variables and yet it must not set that variable within the instance itself.

You’ve got a lot going on here, it’s hard to see exactly where the problem is.

Try just passing an integer into the GI, then changing levels, then check it again. You’ll find it works.

Then it’s just debugging what’s going on here…

1 Like

Is your game instance set to InventoryInst in the project settings? Sometimes you can create a whole blueprint class and just forget to set it.

GI is tucked away in the settings so even I sometimes forget to set it in the prototyping phase :P.

2 Likes

it looks like a lot but thats just because there are lots of values involved. The key part is that I set the SPImage value in one blueprint and then attempt to print the name of it before and after changing maps and its different each time. Nothing else occurs in between the map change.

yep, I must have it set because the other values that I pass through retain their set values. The problem is local to the values set in the second image.

Question 2: Are you setting the values from you game instance by reference? If not they will just return a copy. You need to modify the original value via ref / or by overwriting the value with the outcome (not good for changing single variables though).

1 Like

I doubt that this would be the case because after setting the values I cast to the instance again and then print those values

And the yellow print string variables are the same as the earlier cyan ones?

1 Like

yeah but the ones that I print later are different.


the green values are not the same as the yellow but all logic dictates that they should be.

UPDATE:
The problem appears to have something to do with the blueprint not setting the instance values correctly because I printed it in multiple other locations in the original map and the problem is still the same. I replaced the yellow print to print the same thing across all 6 of the objects that perform the task and only one of them printed the answer I needed meaning that the problem must lie somewhere in the way it is being set and/or printed.
The variable is being set in a way that means that when it is called by the blueprint that sets it it will return the updated variables and yet it must not set that variable within the instance itself.

FYI Get class defaults will only get you the class default of an object so it won’t have any dynamically set variables.

1 Like

thats ok the spell information stays the same, its just which spell I get the information from :slight_smile:

In your set array element try setting size to fit to true. Maybe its not growing the array when needed.

1 Like

I tried it to no avail. I think that it must be a bug at this point tbh, I’ll fire a bug report later today. Thanks for your help Raven.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.