Set Members In Struct From Pawn Only?

Hello, I’m currently trying to add to an Int variable located in a struct every time a blueprint actor is spawned.

I have successfully performed this action using Event BeginPlay when casting to the player pawn to set the variable but I’m trying to move the variable into it’s own struct to be more organized. If I perform this action using an input key it works properly. However when using it on the Event BeginPlay or any event in a spawned actor, it is ignored.

Does anyone know why this would happen?
Examples Below:

This Doesn’t work:

This Does:

Thank you,
Mike

Tried with both variants and it works as expected. I assume you have a simple missunderstanding here. If you got multiple Blueprints spawned in your level they all have their own GameVars Struct. They don´t share one =)

If you want to have a commonly shared one put it into GameMode/GameInstance/GameState or similar. Dont forget to assign your Game Mode or the Cast will fail. Here is a Example: https://i.imgur.com/8fNmnRF.png

Good Luck

That was my mistake, I thought you can access structs globally. I’ve moved variables to the game mode to for fill this purpose.

As a side question, do you know if there is a way to prevent some variables from being persistent in the Game Instance? Or simply reset the Game Instance without restarting the game?

Thank you for your assistance, this has been driving me crazy.

The Variable will always be there you can reset the Values by Hand. The other option would be to use a UObject and set the variable to nothing or create a fresh Object/struct to replace it. Up to you, I suggest a simple reset function.