While our game may be running without any issues in the editor or even in…
Understanding the Blueprint Function Library
Sometimes, we want to create functions which are going to do useful stuff and we don’t care which blueprints can call them. We want these functions to be included in every blueprint in our project. Unreal Engine provides a very easy way to create such functions. Let’s see how we can create them!
Creating such functions
I created a class named MyHelperFunctions which inherits from Blueprint Function Library Class. After the load is complete, you will notice that this class does not contain any default logic or declarations. Instead, the header file contains only the default GENERATED_BODY() macro as seen below:
Right after the GENERATED_BODY() macro I type in the declaration of my function like the following image suggests:
After that, I switch to the corresponding source file and type in the following functionality:
Once you compile your code and switch to any blueprint graph you will notice that if you search the “UsefulFunction” you can call it without doing anything else.
Hi.! Thanks for the tutorials, are so cool. i have a question in this point.
When i call the funcion “UsefulFuncion”, got an error: This s not a MyHelperFuncions, therefore ‘Target’ must have a connection.
What should be connected?
Hello, does this appear on your Blueprint Editor? If so, can you provide a screenshot of your error?
-Orfeas
http://i64.tinypic.com/15ds6x4.png
i review and not sure whats wrong 🙁
I found the mistake, I miss the “public” within the BODY GENERATED () jeje
I’m glad you fixed it!
-Orfeas
It must be a public static function
Hi Orfeas,
Thanks for the tutorial! One thing I notice when I try to follow your tutorial is that you have to declare your functions as static, otherwise the editor would complain that “This s not a MyHelperFuncions, therefore ‘self’ must have a connection”.
btw, I’m using 4.14 now.
Thanks,
Chenglin
Write “static ” before the “void” word, for me works.