Hello,
How can i call a Blueprint function from C++.
So i have a buttonPressed() function that i call in c++
and now i want to do something when the
buttonPressed() function was called in my Blueprint.
thanks for any answers
PS.: If anyone knows how i can play matinee in C++ it would be also helpful
I’m a little unclear on your question. Is the buttonPressed() function created in the blueprint or in c++? It may be be easier to create the function in code with default functionality, then use blueprints for extended functionality as needed
void YYY::XXX_Implementation()
{
//add code here
AAA.doStuff();
}
//the “_Implementation” suffix for the function name is only needed if you use “BlueprintNativeEvent”, and if you want to call that function from CPP, you just call " XXX(); " and not " XXX_Implementation(); "
Adding UFUNCTION(BlueprintCallable) to the function declaration will expose the function to blueprints. Once you add it to the code and compile again you can open up a blueprint with access to the class and type the name of the function into the right-click search menu. Additionally adding “Category = ABC” after BlueprintCallable will allow you to search for the ABC category and anything (function or variable) with the same category will appear.
So first I make a blueprint function called CallFunctionTest.
(In our game, and we call a player a “Survivor”.)
It just prints “Survivor Call Function Test” in pink on the console.
Then I have a static blueprint set of functions like this…
This is a better solution to the problem of a callable blueprint function. My above answer is also useful but in a slightly different scenario. I suggest trying this solution first, and my solution second.
I haven’t tested it, but I assume If the function name you pass into CallFunctionByNameWithArguments() is misspelled or doesn’t exist the compiler (and IDE) won’t catch it, and you’ll get a run-time error / crash? I’d prefer to use a technique that would be picked up before that (for example the technique I posted below) by the complier or IDE. IMHO leveraging the power of the IDE will increase your development speed, accuracy and quality.
I noticed that in some cases, the UFUNCTION is called on the next tick. This causes problems for state machines. Do you know how to ensure a UFUNCTION is called in the same tick as the caller?