game instance variable issue

hi everyone , so I’m kind of new to unreal engine 5 and I was trying to use a game instance for holding a boolean variable (the variable is just for a condition of the key card in inventory)

so player could pass the door if has the key card and stay locked behind the door if hasn’t
(for start I’m just using widgets to show message cause I have 2 lines of error)

-I can see the false respond of the branch , but the true one won’t work
please help

game instance

looting blueprint actor

door blueprint actor

errors

Blueprint Runtime Error: “Accessed None trying to read property K2Node_DynamicCast_AsChecks”. Node: Set KP_Card Graph: EventGraph Function: Execute Ubergraph Kp Clothes Search Blueprint: kp_clothes_search

Blueprint Runtime Error: “Accessed None trying to read property K2Node_DynamicCast_AsChecks”. Node: Branch Graph: EventGraph Function: Execute Ubergraph Kp Secret Door Blueprint: kp_secret_door

full errors

You should store the output of the cast to a variable, or cast the game instance every time you use it. UE optimizes this king of stuff, so what you are doing is trying to access a variable that doesn’t exist anymore.

In short, output pins are “temporary” variables that get deleted soon after. I think on the next tick they will be gone but don’t quote me on that. If you need to reuse the output of a pin, save it as a variable.

Also, just want to point out that this isn’t the best use of the game instance. You might want to move the “Has key” variable (or whatever it is) to the player. Remember that the game instance will persist between levels, so if you want the key to go across levels, then sure, this is the right way!

Otherwise, I suggest player character. Nothing really changes functionally, but it’s more about organization. I am now developing a game for 4 years, had to restart it 3 times because of my nonsense organization and programming conventions. Don’t make my same mistake!

well after two hours , looks like I forgot to set the game instance in project setting :joy: :joy:

lol happens