I’ve found some answers to this question, but none of them seem to apply here. I’ve read this error occurs when the header function does not correspond to the class function declared, but that is not the case. If I made this function BlueprintCallable, it builds, but not with these for some reason, but I need the function to be callable from an event. Even if I make it just BlueprintImplementableEvent and delete the function from the class file, it whines about the function not being declared in the class file and fails to compile. Thought may be it has to do with the string required parameter, but alas, it still gives the error.
Luckily, Rama explains the simple solution to this issue on the UE4 wiki page about BlueprintNativeEvent functions.
Check out the section way down at the bottom called “Overloaded function not found…”
Basically, the way I understand the issue is, during compilation the Unreal Header Tool sneakily generates a signature for your BlueprintNativeEvent function that passes your function parameters by constant reference instead of simply by value. In other words, the UHT sneaks in a “const” and an ampersand where us well-meaning programmers don’t expect 'em to be.
Thankfully, the fix is easy: just change your function signature to pass the FString parameter by const reference instead, which will cause it to match what the UHT mandates. Specifically, try changing your function declaration to:
void AProjectileBase::FiringSetup(const FString& directionFace)
Finally, based on your screenshot, it looks like you’re likely to encounter another problem that I just wrestled with yesterday:
When defining your BlueprintNativeEvent function in your .cpp file, you must add the _Implementation suffix to the function name, or else you’ll get compiler errors regarding duplicate declarations or some such. Rama explains this issue also on that same Wiki page.
Hopefully, with that, things make slightly more sense and you can get your code compiling again. (I know I was shaking my head yesterday.)
I made a response, but apparently this has an auto-detect for even a mild cuss, so I guess I’ll have to wait a million years for it to be verified. Or may be, you know, I could get the option to see it myself and edit it out, because I didn’t know that was a mechanic of this Q&A thing.
Forget it, I’ll just roughly rewrite what I was going to say.
This just made it more confusing, could I please get an answer specifically to what I need to change the function in header and class files, because I’m getting conflicting information all over and it’s not working:
Sorry for the confusion.
Unless there’s something I’m missing, here’s how you should need to set up your function as a BlueprintNativeEvent:
Header:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Firing)
void FiringSetup(const FString& directionFace);
Source (.cpp):
void AProjectileBase::FiringSetup_Implementation(const FString& directionFace) {
// Default implementation code goes here
}
Note that in the .cpp file, the function name is changed to include the _Implementation suffix. Without this suffix, you’ll get the “already defined” compiler errors.
Hope that clears things up.
It seemed to show this error:
But then after giving it a while, the error went away, I was able to compile and the mechanic I was trying to implement works marvellously, thank you
Thanks mate! This solved the issue. I really don’t understand why this is not documented.
The only thing stated in ObjectMacros.h is:
/// This function is designed to be overridden by a blueprint, but also has a native implementation.
/// Provide a body named [FunctionName]_Implementation instead of [FunctionName]; the autogenerated
/// code will include a thunk that calls the implementation method when necessary.
BlueprintNativeEvent,