[Feature Request] BP Static Support

Is there any plan to expand static variable and function support in BP? There are ways of “hacking” in each, but, by nature of being hacks, they’re inefficient or inelegant.

Faking Static Variables:

A) Declare static variable in C++; make static Getter and Setter functions for BP access.

  • requires declaring those two functions
  • can’t only set the variable in BP through function, so only at runtime or in construction script

B) Declare non-static variable in C++; use DefaultActor’s member for everything

  • wasted member in the instances

Faking Static BP-Implemented Functions:

A) Non-static BP-Implemented function that is called by the static function

  • have to declare two functions to do the job of one

Even if all you do is hide the above methods behind UProperty and UFunction specifiers, it would at least make things cleaner

By the looks of it, though, you can’t make a BFL with functions defined in BP and accessible to C++.

Hey

If you want to be able to access a function from multiple blueprints, you can use a blueprint function library. Functions defined in a blueprint function library are available for other blueprints.

Cheers

You can create a new class based on the BlueprintFunctionLibrary class. Static functions inside your custom BFL class can then be used in C++ as well as called from blueprints.

UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = “Test”)
static void TestImplemented();

results in

error C2352: 'UObject::FindFunctionChecked': illegal call of non-static member function

Same for BlueprintNativeEvent. Is there some other means you’re suggesting?

BlueprintFunction Libraries need to be already implemented. BlueprintImplementableEvent is illegal on them. BlueprintCallable is the only modifier you can use.

Also: Static Is Evil. It’s a bad design if you need to rely on static variables. Most of the time they are bad do debug and you can never guarantee which state a static variable will have at runtime.

“BlueprintFunction Libraries need to be already implemented. BlueprintImplementableEvent is illegal on them.” Gosh, it’s almost as if that’s why I’m requesting the feature.

“Static is Evil.” Static has a purpose; one that appears quite frequently in my project: shared data across instances. I think it’s bad design not to make use of the tools a language provides.

“you can never guarantee which state a static variable will have at runtime.”
I take it you’ve never heard of Static Const? For that matter, if I’m a good programmer, I have as much guarantee of the runtime state for a static variable as a non-static variable.

You’re confusing “static” with “globals.”

Static variables are an incredibly powerful tool in C/C++/C# and all other object oriented programming.

Imagine this scenario. There is a menu where the player can look at the stats of the enemies types he has discovered. He can see how many he killed, what there health/defense/strength/etc. are. How would I do this without static variables?

If I had them, it would be as easy as accessing the class, preforming an enemyClass.KillCount++ and then I can just do enemyClass.MaxHealth to get the max health for all instances, without having create a new instance or store it else where.

And what if I want the enemies to behave differently the higher their kill count is? Maybe they have more power, or health, or a higher AI system?

With static variables, I have the power to change a variable in ALL instances of the class at once. And I can even reset it back to zero when the level ends, or the player dies, i.e., guaranteeing what state it is in, just like any other variable.

This works, but its not directly attached to the class, which makes it too public, and you can’t store variables on them. I normally have to make an actor component and attach it to a persistent object, like the GameMode, or the Player, but its just a workaround, and I’d much rather prefer the more direct approach of static variables, to make everything more simple.