Ben is wrong about BeginPlay and Constructor timing in C++ vs Blueprint?

Ben seems to imply that the C++ for Beginplay runs before the Blueprint, but the Donkey logs tell a different story here:

The C++ constructor definitely seems to run before it’s blueprint counterpart, but when it comes to BeginPlay() the opposite seems to be the case. Did I misunderstand?

Where did you put the log? Super::BeginPlay is what would run the blueprint’s begin play

1 Like

Ah, so if I put the log above Super::BeginPlay; the C++ code would execute before the BP? I was under the assumption that the Super Statement needs to be the first line in a virtual method. You can see that it’s happening in the lecture video itself here:

The blue highlighted is the blueprint log, and the green highlight is C++. As you can see, it calls the C++ constructor, the BP constructor, then the BP BeginPlay, then the C++ BeginPlay.

If Super:: BeginPlay is what’s executing the blueprint’s begin play, and you can insert code above or below the Super:BeginPlay then I don’t know how accurate Ben’s statement about execution order is.

I forget what Ben says exactly but how is the order execution incorrect? In order for Super::BeginPlay() to be called it must be from with the C++'s BeginPlay() function.

Sorry, perhaps incorrect is the wrong word. What I mean is that the lecture seems to imply that execution order is C++ > Blueprint, but the logs (as they are written now in the lecture) can confuse a student because they seem to contradict that. Maybe something that could be clarified in a future update. Regardless, thanks for the help, I get it now!

2 Likes

I’ve left it up to Sam to decide what to do about it. Thanks for reporting :slight_smile:

Thank you for asking this question! I had the same thing in my mind. According to the logs it does seam like the BP Begin Play() runs before the C++ BeginPlay() which was confusing for me.
But when the Super::BeginPlay() in the C++ is calling the BP’s BeginPlay() then it becomes obvious that the C++ BeginPlay() runs first, but just in order to execute the BP’s BeginPlay() first? Before executing it’s in C++ BeginPlay() code?
Still somewhat confusing … looking forward to see in the next videos what we actually do with that knowledge

To put comments in code

void AExample::BeginPlay()
{
    // code here is executed before BP Begin Play
    Super::BeginPlay(); //BP BeginPlay happens
    // code here is executed after BP Begin Play
}
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms