C++ create event for Blueprint

In my header file public section:

// Create Event
UFUNCTION(BlueprintImplementableEvent,  Category = "BaseCharacter")
void OnDeath();

Error: waitmutex -2015 exited with code -1 “Microsoft.MakeFill.Targets” line 37.

Okay so some Unreal macro doesn’t like the code above? According to other topics on the AnswerHub this is the way to implement it. Why is UE4 throwing a compiler error in Visual Studio?

I tried adding the code to the cpp as wel (even though this should not be implemented but just to try it out):

void ABaseCharacter_C::OnDeath() { }

But same error. If I remove all of the code above then everything compiles again just fine so it’s not another piece of code. I also tried changing the name of OnDeath to something else in case it was conflicting with another name but that didn’t work either. I also tried adding “virtual” but that raised the same error.

1 Like

Is your actual class name ABaseCharacter_C? That doesnt look right. Can you rename your class to ABaseCharacter and see if it fixes the issue?

Try to add

virtual void OnDeath_Implementation() {}

Same problem. Also I found this:

4.8 Patch:
Removed “virtual” keyword from several engine-level BlueprintImplementableEvents to conform to the new “BlueprintImplementableEvents should not be virtual” standard.

So “virtual” is probably no good anyway in 4.11

I can suffix my C++ classes with an underscore _C if I want too (I hope). That should not cause any problems. It’s not a typo. My class is actually called: BaseCharacter_C.

Hey there,

yes you’re right, you don’t need the C++ Implementation.

BlueprintImplementableEvent only has a Blueprint Version.

BlueprintNativeEvent would have the C++ AND Blueprint Version.

The code looks fine, that’s how I did it too. Is this all error you get? Could you check out the OUTPUT tab, after the Compilation failed? The one you normally get is the ERROR LIST tab. When you open the OUTPUT tab, scroll up till the first error and check if that helps you (if not, quote the whole Output, starting at the first Error, here).

You should find the OUTPUT tab at the bottom of VS:

http://puu.sh/omMew/cad753cb65.png

1 Like

Can you show a more about ABaseCharacter_C declaration?

virtual keyword for this type of events is working in 4.11. At least for me

Strangely this particular error was fixed by restarting the UE4 Editor and Visual Studio (I noticed I was missing the compile button in UE4). I noticed that starting UE4 before VS can lead to weird behavior and that compiling the project in VS while opening the project in the UE4 Edtitor can also be bad. And missing the “Compile” button in UE4 can also lead to weird behavior. And sometimes when the UE4 Editor complains (spams log with those errors) about a None-class restarting the Editor fixes it.

However I still have a problem regarding the implementation (which I want to add in the blueprint actually but okay I guess I still need an empty implementation in C++ at the very least):

void ABaseCharacter_C::OnDeath_Implementation(){}

Result:

void ABaseCharacter_C::OnDeath(){}

Result:

I also tried:

// Create Event
UFUNCTION(BlueprintImplementableEvent, Category = "BaseCharacter")
void OnDeath();
void OnDeath_Implementation();
// in cpp file:
void ABaseCharacter_C::OnDeath_Implementation(){}

It compiles but the event never fires when I call it with either OnDeath() or OnDeath_Implementation(). Also no errors, not in VS, not in UE4. But nothing happens:

87327-vs3.png

Clearly I’m missing something simple but the tutorials I find online all tell me to use “_Implementation” suffix. but it does not work.

As i said, a BlueprintImplementableEvent does NOT have a C++ Implementation.

You don’t need the

void OnDeath_Implementation(); 

nor do you need 

void ABaseCharacter_C::OnDeath_Implementation(){} or 
void ABaseCharacter_C::OnDeath(){}

You only need the header file part

// Create Event
UFUNCTION(BlueprintImplementableEvent, Category = "BaseCharacter")
void OnDeath();

All logic will be added in the Blueprint Child Class. And the function, in C++, will be called via “OnDeath();”.

ALSO: Your Code is not compiling. It’s still failing!

Remove the things i mentioned and recompile. Then check if there are still errors.

NOTE

Recompiling while the Editor is opened is called “Hot Reloading”. This is not working well if you add new declarations to the Header File. You can use it if you make smaller changes to the implementation of functions, but if you change the declaration in the header file, you need to restart the Editor. Otherwise changes could not get through.

You should also set VS to “Development Editor” and compile the Game by right-clicking your Project in the Solution Browser of VS and hitting “Build”.

For debugging C++ code, set VS to “DebugGame Editor” and hit the Player Button at the top.

Of course:

Header file: http://pastebin.com/NuPB1xNx

CPP file: http://pastebin.com/02rNGagP

I was following the twinstick tutorial and now I’m trying to expand it. So if it looks familiar, that’s why.

“For debugging C++ code, set VS to “DebugGame Editor” and hit the Player Button at the top.”

“You can use it if you make smaller changes to the implementation of functions, but if you change the declaration in the header file, you need to restart the Editor. Otherwise changes could not get through.”

Oh. I see. That changes things. Now it does work without the implementation! I usually press F7 to build the entire solution in VS and don’t restart UE4 but it seems required sometimes.

So the solution was: No implementation, only add code to the header file and change the Visual Studio debugger to “DebugGame Editor” and restart UE4 Editor.