I have attached the images of what I am doing below. I have the player colliding with an object that is the “Clue” and once that happens it is destroyed. I want to also set a variable to True by doing this. Then in another Bp that is the “Switch” I want to check if the variable is true and then allow the player to press a Key and open a door. So far nothing I have tried makes the door open. Any Ideas why its not reading or setting this variable to True? Please Help!
The problem here is that “has clue” exists 2 times in 2 different blueprints - once in the “clue” blueprint and once in the “switch” blueprint. The big problem here is that these 2 variables have nothing in common besides accidentially" having the same name. If you want a variable to be “pseudo global” then I’d store it in the game mode. Make a “has clue” variable in the game mode (make your own custom game mode like “MyGameMode” or so) and then in your game mode have 2 functions called “SetHasClue” and “GetHasClue” then you can call them from any blueprint with something like “Get game mode”–>“Cast to MyGameMode”–>“GetHasClue”. UE4 is a bit confusing by the lack of a real “Global Variable” system, but by working around throgh the game mode you have an easy workarond. Note that this is not suitable for multiplayer games - there are other workarounds for that.
So are you saying that I have to create a custom game mode BP ? Once I do that how can I create variables to store there?
Yeah I like having a custom game mode since you can cast to that from pretty much everywhere. In the game mode you open the full BP editor and you can create variables and functions like in any other blueprint
I think what is escaping me is how to not have the variable be just an empty object. The clue BP has a static mesh actor in it, which is a piece of paper. Can I tell it to set the variable once the mesh is destroyed? Forgive me I am no real programmer…
The variable - it is probably a boolean - is by default eitehr just true or false (I guess you want it initially to be “false”) which you can set when you create it in the game mode. think of that as your central memory in the game - that big synthetic brain that secretly hovers high over your game and always watches you - everyone can access or edit it from everywhere that way.
Yeah when you got it in your game mode you can read or set the variable from pretty much anywhere - you just “cast” to your “GetClue” or “SetClue” function in the game mode (it is possible, but try to refrain from directly changing variables from the cast, make a function in game mode to get or set them). Think of the game mode as a cheap way of storing global variables you can access from everywhere.
Perhaps you are casting to the wrong object, happened a few times with me in the past, you may add a print on the cast failure.
I got it figured out now… Set my variable to an integer and checked the number if clues to required number of clues… Press Z and PRESTO! The door opens! Thanks for the help guys!