Super::BeginPlay();

Hello, I’m following the Unreal Engine C++ course and I’m half-way through the bull/cows game. Something that I’ve been wondering for a while is the purpose behind this line in the BeginPlay() function:

Super::BeginPlay();

What does it mean and why is it there?

Super is a type alias for the parent class (aka the super class). It is one of the things the GENERATED_BODY() macro does.

So for the UBullCowCartridge class it’s just an alias for UCartridge. So you are just calling the parent class’ BeginPlay function which does this

1 Like

Does this mean that in the following…

void UBullCowCartridge::BeginPlay() 
{    
    Super::BeginPlay();

    SetupGame(); 
}

" Super::BeginPlay();" calls the BeginPlay() function in UCartridge, and then that UCartridge function (which also includes the line “Super::BeginPlay();”) then additionally calls the “virtual void BeginPlay()” function in ActorComponent.cpp?

Yes. It’s essentially extending the function.

Demo: Compiler Explorer

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

Privacy & Terms