Hello everyone, need your help. I need to create a variable that is gobal, so it can be edited in different blueprints in order to be used as a condition. In my game I have 3 targets, which when hit would add +1 to variable. In the end a door opens only if this variable has the value 3. Is it possible? If someone can help me was thankful
In a simple singleplayer game you can create the variable in your playercontroller. You can access it from everywhere by using getplayercontroller (index 0) and cast ist to your playercontroller class. And dont forget to set your playercontrollerclass as default inside your gametype
Hello, thanks for the help, but nevertheless have a problem! I’m a little confused, I tried to create a variable in MyCharacter but can not access it in another BluePrints. I am creating in the wrong place? How do I access PlayerController? greetings
Thank you, already managed to solve my problem: D thanks for the help
Keep in mind this isn’t great for all implementations, such as when your PlayerController may change during gameplay or across levels or if there’s a variable that would be relevant to all players, not just a specific player. I recommend in these cases, instead of placing your “global” variable on the PlayerController, to place it in the GameInstance.
Create a new GameInstance blueprint and set it to the project’s GameInstance (under Maps & Modes inside Project Settings). Then you call and cast it in your blueprints just like you would do with the PlayerController above.
the advantage to using GameInstance is that it persists for the life of the game. This will allow you to carry variables from say, a Main Menu Options screen over to a loaded level map without having to create, save, and load using a SaveGame blueprint.
that’s a good design tip, thanks for sharing.
Jared Therriault thank you so much!!!
You saved me from massive headaches, hair loss, depression and anxiety.