What is Super class and when exactly I use it?

I know it may seems a very noob question, But really I spent a lot of hours to find out what and when I use Super class

there is examples I Could understand such as Super::BeginPlay();
but what I couldn’t understand why we used it like so Super::PostInitProperties(); or Super::PostEditChangeProperty()

however there is no problem with me understanding the API itself, But still “Super” can’t understand it’s specific use exactly .or what does it mean?

Help please

thanks

This is something basic of C++.

If you have a BaseClass where you defined a virtual function and gave it some logic, and you create a child class from it where you override this functions, you can make sure that the BaseClass code is still called by calling “Super::Function()”.

6 Likes

Are you sure? I’m new to C++ but after some quick googling around I can’t find any reference to Super:: being a C++ standard feature.

1 Like

Yes i’m sure. Super:: itself is not basic C++. In C++ you would go with

void ChildClass::Foo()

{

    BaseClass::Foo();        

}

But in UE4 we just use Super::Foo();

9 Likes

thanks a lot

Thanks also from me.

1 Like

Super is very important for inheriting basic functionality from a parent class. Use it extensively, if you want to save yourself the time.

1 Like

UE support this by using typedef

262936-15453106912245.png

It’s cool

5 Likes

void AClassSample::BeginPlay()
{
Super::BeginPlay(); // we call default begin play from Super class
// But for what? Default Begin Play Function contains
// Some methods, that are neccessarry to execute it as
// actually BeginPlay function. but when we override it,
// all the functionality of default BeginPlay disappears.
// Because of overriding, we need at first to call default
// BeginPlay function, to include default function logic,
// and then do the rest of things.
}

2 Likes

void AClassSample::BeginPlay()
{
Super::BeginPlay(); // we call default begin play from Super class
// But for what? Default Begin Play Function contains
// Some methods, that are neccessarry to execute it as
// actually BeginPlay function. but when we override it,
// all the functionality of default BeginPlay disappears.
// Because of overriding, we need at first to call default
// BeginPlay function, to include default function logic
// from Super class, and then do the rest of things.
}

Good followup - as the accepted answer described what super is generically in programming, but doesn’t exist in standard c++ because of multiple inheritance ambiguity. Hence OP’s long fruitless search.

A macrofied class system like UE has can however safely mimic it with a typedef.

1 Like

Why we want to call base class function ? What is the purpose of it ?

Because in some cases we want to allow the engine to do a lot of things and to follow its logical flow.
Two messages above yours, NkIceberg went through explaining Super::BeginPlay() as an example.

It IS cool

So if I have

UCLASS()
class MYPROJECT_API AParentClass : public AActor
{
    GENERATED_BODY()
    virtual void Tick(float DeltaTime) override;
    virtual void NonUeFunction(int myParam);
}
void AParentClass::Tick(float DeltaTime){
    print("ticked off without supering");
}
void AParentClass::NonUeFunction(int myParam){
    print("custom parent func called");
}

and

UCLASS(BlueprintType)
class MYPROJECT_API AChildClass : public AParentClass
{
    GENERATED_BODY()

    virtual void Tick(float DeltaTime) override;
    virtual void NonUeFunction(intmyParam) override;
}
void AChildClass::Tick(float DeltaTime){
	Super::Tick(DeltaTime);
}
void AChildClass::NonUeFunction(int myParam){
    Super::NonUeFunction(1);
    print("custom child func called");
}

and then I start up my game and try to spawn a child class?

  1. Will the ChildClass’s Super::Tick(DeltaTime) reach the Base AActor class from the child class, or will it stop in the ParentClass::Tick and break?

What if I then call

InstanceOfChildClass->NonUeFunction(3) 
  1. Will both child and parent NonUeFuncitons work because we get the use of Super with the UCLASS() decorator or something? Or will it break because “Super” is only manually set in Unreal Source classes?