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.
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.
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.
There should be some method to get/set a GLOBAL value without casting…like actual global general variables.
How do you use a function library where you want to read some last function call value, do some process and then store the last result for the next function call without lose performance casting inside the function?
Create an interface and implement it in any of the framework classes - bam, global variables, no casting. Also, you’d be using getters, like a proper programmer.
Do note that 9/10 people in the know will tell you that global variables are a bad idea. The idea of OOP is to encapsulate and keep things on the need-to-know only basis. Not the other way round.
It’s just bad practice imho. Once you structure your code properly and learn blueprint comms (direct, dispatchers and interfaces), you’ll never want or need global variables.
And if you ever need to fetch something, it’s always a cast-away in a framework class that is already loaded, making things somewhat global anyway.
But an interface to a framework class that holds a refence to a data base actor is not a bad idea.
I think I have a solid understanding of tickers dispatchers, timers, timelines, delegates, etc but somehow I always avoided interfaces. Usually I share common data in gamemode or just cast if really needed. But I in this case I want to do a dumb time measure functions library just to measure time of any block of code on start and end . For example:
you are counting in Gamemode and not in the library function.
So if you want to use the function in Playercontroller you must count inside it too…I want the library function to make the task if not if useless
What i want is this:
in gamemode you call in the ticker CountSomething and it prints in the screen 1…2…3…4…no math in gamemode. that is why I want to get the value inside the function, add and store the value again.
is ok if the value is stored in gamemode but is not ok if the math is in gamemode.