Download

Static Functions in Blueprint?

Is it possible to create and use static functions in Blueprint such as class’PlayerPawn’.static.GetHealth() without spawning an instance of the class?

Why would you want to do this?

This is a bit of an odd question, especially given player health being used as an example.

Without an instance of the class, mostly the problem would be that any variables would not be initialized.

I’m not entirely sure of the implementation of the function you described above, i would presume that it uses some form of argument to identify an instance of a player pawn to act on.

I used a blueprint macro library to emulate a static function:

006b10442f0a468199bb10bc0a1e1cad7377b742.jpeg

macro is actually more like…macro.
And Tucarius is right, I don’t think you can do static function for blueprint, but you can always create a “static_YourBlueprint” item that you don’t use, thus you can still get default value.
BUUUUUT, there are already people mention how to get/set default values of your variables, so I don’t see a point to use a static function to do this.

I was looking for the same solution and finaly came to this: ContentBrowser -> RightClick -> Blueprints -> Blueprint Function Library

2 Likes

Static Functions in Blueprint? - #5 by HawkPride - Blueprint Visual Scripting - Unreal Engine Forums the best solution, @HawkPride thank you very much!