Overriding beginplay in c++ and BP

I have a subclass of actor written in c++, which needs to perform some operations on BeginPlay. That’s easy enough to do in c++, but I want any blueprints that inherit from this class to be able to implement this event as well (and call the parent BeginPlay if required).

In order to try and solve this, I added “UFUNCTION(BlueprintNativeEvent)” ahead of my “void BeginPlay()” definition in the header file, and changed the code in my cpp file to BeginPlay_Implementation(). However, this doesn’t work, because now I have two BeginPlay functions defined. If I change the category of the UFUNCTION, it works, but this seems like a hack.

Can anyone give me an example of code where the BeginPlay_Implementation() function is called AND the Event BeginPlay [blueprints] being fired?

edit: Turns out I wasn’t calling Super::BeginPlay() in my c++ code.

The Blueprint event is actully ReciveBeginPlay() and it called in BeginPlay in AActor class. But i thing what you looking for is how to call Super::BeginPlay() in blueprint, you can do that by right clicking the event end there should be option to create call to paret and its gonna create orange node where you can call event in parent, its equivlent os Super call.

Unfortunately, RecieveBeginPlay is only BlueprintImplementable, so I can’t override RecieveBeginPlay_Implementation(), which is what the blueprint “Call to parent” is looking for. Turns out the whole problem was that I wasn’t calling Super::BeginPlay() in my c++ class, so AActor::BeginPlay (and hence RecieveBeginPlay) was never reached. Moral of the story: always call your supers. Now both the c++ code and blueprint code fires, even without a call to parent.

Now the hypothetical question is: Is it possible to OVERRIDE the BeginPlay function completely in blueprints?

No, because BeginPlay is not blueprint event to begin with, 2nd it won’t stop beginplay being called nativly where blueprint has 0 control over code flow.

Ok, thanks for clarifying :slight_smile: