How to Call C++ function from Blueprint?

I’m trying to use my simple “PrintText” function that I have created for test in c++ to call from blueprint but I’m getting an error every time I try to call the “PrintText” function from Blueprint. I don’t know what should be the target or the object after casting. The MyBlueprintFunctionLibrary is inheriting from UBlueprintFunctionLibrary. Any Help?

I’m trying to call the “PrintText” function from the “Level Blueprint”.

MyBlueprintFunctionLibrary.h

MyBlueprintFunctionLibrary.cpp

Before casting to MyBlueprintFunctionLibrary. Target is unknown.

After casting to MyBlueprintFunctionLibrary. What should be the Object?

1 Like

Functions inside a Function Library class should be static :slight_smile:

1 Like

Yes, I know if I make the function static then there is no need to specify its target, but I would like to know, how can I call a C++ function from blueprint when it’s not static?

The function library is a utility class meant to be called from anywhere and therefore static, while any regular class don’t normally use static functions and can be called if they are BlueprintCallable and you have a reference.

Well, then you make a class that is not a Function Library, such as an Actor class!
Then you don’t need to make it static since the Target will be the actor you create from that Actor class.

Blueprint Function libraries do not have an object that you can Target it. It’s a class that provides global functions therefore they must be static.

To use this function in Blueprint, just use the tag UFUNCTION(BlueprintCallable), like GarnerP57 said. This should work :slight_smile: