Common static variable across blueprint objects

I want to have several static values that do not change between different objects of the same blueprint. For example - unit build cost. Would it be possible to have something like this accessible from a blueprint class variable (the purple type) and not object reference?

Blueprint does not support static variables as well global variables, you would need to make single global object to hold such variable or use existing one (like GameMode class) or use other method of containing unit data. In C++ itā€™s easier, you not only can use static variables, you can access variable defaults via default object in UClass (thats what you see as purple type in blueprint).

I think ability to get class defaults in blueprint is great idea for suggestion in feedback forum :slight_smile:

1 Like

alright thanks :slight_smile:

Wow, thatā€™s - strange.
So if I have a class which as a property like ā€˜nameā€™ I am not able to access this without creating an instance first, getting the property and then destroying itā€¦? Really?

Well if you want to access defaults you can do that via CBO, which if iā€™m not mistaken support to access it via blueprint will be officially (since you can make it available to blueprint easily via C++) added in 4.9

1 Like

You can do that now in the 4.9 preview I think.

a little hack if you just need variables to be readable from everywhere:
create a macro library and define a macro with just outputs for those values

Iā€™m e.g. using that for having a central place to modify a global color scheme that needs to be accessible across different blueprints

1 Like

instead, you can just define a getter function inside your C++ class.

UFUNCTION(BlueprintNativeEvent, BlueprintCallable, BlueprintPure, Category = ā€œayy lmaoā€)
MyType getMyStaticVarValue();

What I did was use a Data Table. Is there any better solution? I wish you could use something like a static variable and make use of inheritance.

EDIT: You can use getClassDefaults function using Blueprints!

i use get player characterā€”> cast to topdowncharacter ā€”> set (any variable of my character) and this is global variable :slight_smile: is this solution fine? it works everything in my game