Where lost Instance variable

I need transfer quests from level to level. For this is array QuestActors. I assign it value in widget, after button clicked.

So. Value is assigned, and can be printed, it’s ok.

Then. I try get value from Instance on next game level. But array is empty.

Where gone variable…?

  • how are you testing the emptiness?
  • Is AsGameInstance valid in the second pic? If so, could you show how its value is assigned?

On second pic node “get” I connect to “print”. It print nothing. “Asgameinstance” must be valid. From there Character get “health” “experience”, and all this variables on screen. For a while I not check at this point. “Level” value not lost on new game location, so game instance must be valid. May be I try check it. Today too late to launch Editor, for 23 gb it loaded long time.

First picture from widget blueprint. Array assigned on button click. There array valid, I can get element and print it. This visible on screen. New level load after this widget clicked, so value seems lost… But other variables like health and level integer not lost.

There some trick out there…

I found that Game Instance not save references… So this array in Instance assigned as reference to other blueprint… Look like I need create new array and assign him values with loop (for each loop as example).

Is some advice how do it better?

You will need to save the game at some point, right? Best handle it now. You wouldn’t save the refs themselves, but the data that represents the actors / components / objects / widgets. And then respawn what is needed from said data.

Object references can be saved but if the objects themselves get destroyed (during level transition), the refs now point to nothing until their values are assigned again.


Alternatively, seek plugins that simplify the manual labour:

There may be similar ones on the marketplace.

Thank a lot. It can be useful. Save game in my game working ok on this stage.

I talking about save variable array through Game Instance. I found Game Instance not keep refs. So look like I need recreate array I need with no refs. How to do it accurate? Any advice appreciated.

I see array I wish keep through levels is reference to blueprint. I think this is reason why it lost between levels.

What would be the point of keeping refs if your quest objects no longer exist? The GI would keep simple vars like bools, floats and ints. But you’re talking about references to your objects which are no longer there - providing I understood what we’re working with here. You have an array full of nothing.

Long story short - you cannot save actor references. If you quit the game and boot it again, you need to recreate the objects. Same with level transition, and it does not matter where the array of now null refs is being kept. Essentially, you end up with this:

image

There are references in the array but they do not refer to anything. Since your save game is working - save the Quest Actors’ data to a SG object. Load a new level, spawn Quest Actors and add them to the array - remember to clear it first - it’s full of stale refs. Or Set Array Elements instead if that’s more convenient.

This array just need to complete quests by function and keep note in player quest journal.

Really on other level those NPC will destroyed and respawn when player visit those levels again.

MasterQuest and QuestManager blueprints are respawned, but function “CompleteSubGoals” need ref to MasterQuest blueprint. So every time I need recreate this array. It awesome :sweat_smile: . Unreal Engine created not me. They better know why they insist us do something again and again :smiley:

As a result I think I understand: references not keep with Game Instance. Next stage is my job. This post can be marked as solution. :smiley:

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