It appears that if you have BeginPlay event in BP parented from C++ class then BP’s BeginPlay executes first and then BeginPlay defined in C++ class. This happens even if you haven’t done “add parent function call” to add parent node. Even if you do add parent node for BeginPlay it has no effect on above behavior. In other words, BP’s BeginPlay event always gets called first and the BeginPlay event in C++ next - no matter what you do.
Repro Steps:
Create blank Unreal C++ project
Add C++ Pawn class called MyPawn
Right click on C++ class to create Blueprint from C++ class, name it BP_Mypawn
Add BeginPlay event in C++ as well as BP, print some debug string from both
Drag and drop BP_MyPawn in the scene
Hit play. Observe both debug string gets printed, one from BP first.
Is this correct behavior? My assumption from the current documentation was that BeginPlay in C++ would not get executed if I’d BeginPlay in BP child class - unless I added a node for parent call.
The code implementation of BeginPlay will always trigger, whether BeginPlay is used in the blueprint or not. The blueprint’s call to Being Play is determined by where the call to Super::BeginPlay(); is in code. If your call to Super is before the debug message in code, then you’ll see the blueprint message print to the screen first. But if your code debug message is before the call to Super, you’ll see the code message print first.
Thank you. This clears up a lot. I’m still bit confused because I thought Super is alias for base class not derived class. So when I call Super::xxx() it should invoke code in base class. My assumption here is that Blueprint is derived class of C++ code class. So your explanation for Super seems counter intuitive.
Also how does parent call node in blueprint effect all these? It seems to have no effect on the order of BeginPlay between Blueprint and C++.
The Super::BeginPlay() call does call the base class of C++ code class. In the base class however there is line of call RecieveBeginPlay() which redirects the call to Blueprint’s the BeginPlay(). Thus C++ code controls exactly when (and if ) Blueprint’s event gets called.
Hey ,
Can you explain a bit more on this please? Because what i’ve tried is that i commented out Super::Beginplay() in my pawn class (C++ ).therefore i’m not executing the bp begin play. What i want to know is that if u set your derived bp class as default in game mode, then why base class( C++ version gets called) begin play executes? An explaination would be very helpful.
Thank you…
The BeginPlay node that you you see in a blueprint is badly named in my opinion.
It is actually a function that is called by the genuine BeginPlay in the parent class. The node appears with the name BeginPlay but it is actually function called ReceiveBeginPlay().
Take Actor as an example class. In Actor.h you will find this:-
protected:
/** Event when play begins for this actor. */
UFUNCTION(BlueprintImplementableEvent, meta=(DisplayName = “BeginPlay”))
void ReceiveBeginPlay();
/** Overridable native event for when play begins for this actor. */
virtual void BeginPlay();
And in the Actor::BeginPlay() you will find that it calls ReceiveBeginPlay() - and that is your BP node which has the DisplayName = BeginPlay.
void AActor::BeginPlay()
{
// there is a bunch more code here but it is not relevant to this discussion