Download

Global Variables for every Blueprint scripts?

Hi everyone,

Please forgive me I’m pretty new in Blueprint. is there a way to declare a set of global variable like colors and strings that I can call in specific blueprints?
Basically I’m creating an interface and I would like to get the same set of colors and datas instead that change the same colors, names and datas for each blueprint script.

Many thanks

You could create a Blueprint function library that provides functions that just return the desired values.

Can you please share an example?

any example or solution?

You can set them in the game mode and pass them to the game state. Then Get Game State -> Variable

Every Variable you create inside a Game Instance can be get/set globally and is persistent.
​​​​​

Ok this is because I need to have same colors and strings for every control in the interface. So let me try to create variables in the game instance, but how can I get them in a blueprint?

First go to Project Settings and under Maps & Modes set your Game Instance to be the default one. Then you have two options, one is to “Get Game Instance > Cast To NameOfYourGameInstance” and get the variables that you need, the other option is to create a Blueprint Function Library and inside it create a new function that does the same thing and connect it to be the return value, after which you can simply call it from any blueprint.

I cannot get my variable to a blueprint code. Could you please share an image?

Ok so basically this is what I need to do and it is the common work in every development stage.

  • Declaring some global color variables in GameInstance
  • Change the UI based on those variables

Could you please share an example?

Like this:

  1. Make your game instance, right click in content browser and create a blueprint:

  1. Open your game instance and put variables in it. I made one called GlobalFloat and set it to 23.6

  1. It’s accessible anywhere, like this:

Oh many thanks ClockworkOcean
At this point I think it’s coming convenient to use textures and images and design a bit less dynamic interface in terms of software. But it looks better.