Need explanations about Super::

Hi everyone,

I think I’ve misunderstood inheritance and maybe our wonderful community can help to see clearly.

I have my CustomSpringArm whivh inherits from USpringArmComponent,

I overrided UpdateDesireArmLocation and BlendLocations.

Inside my custom UpdateDesireArmLocation I have a call to Super::UpdateDesireArmLocation()

and inside the parent UpdateDesireArmLocation there is a call to BlendLocations.

BUT, the called BlendLocations goes to the parent version and not the child one.

Normally, does it should not be the child implementation of BlendLocations which should be executed ?

Best regards everyone,

Alex

PS: Here is my declaration of my BlendLocations override :

virtual FVector BlendLocations(const FVector& DesiredArmLocation, const FVector& TraceHitLocation, bool bHitSomething, float DeltaTime) override;

The derived BlendLocations should be called even if you call the Base class UpdateDesiredArmLocation. When the base class call any virtual function it will call the most derived function of the object except if it specifically calls a member function with the scope resolution operator ::

This is why Super::YourFunction isn’t calling the derived class but the base class. Super is a “keyword” made in Unreal for your convenience that is a typedef of the parent class.

USpringArmComponent::UpdateDesiredArmLocation is the same as Super::UpdateDesiredArmLocation if the class is derived from USpringArmComponent.

And if you use instead of super USpringArmComponent::UpdateDesiredArmLocation() ? I tried it and same result :confused: What should I do to make this work ?

Thank you for the reply

That is difficult to answer without seeing the code. Are you sure you are actually using your derived class and not the base class component?

Yep I’m sure because it’s calling my first derived USpringArmComponent::UpdateDesiredArmLocation(),

Here is my code (it’s an extension from the article from 6 Ingredients for a Dynamic Third Person Camera) :

void UHoatCameraSpringArmComponent::UpdateDesiredArmLocation(bool bDoTrace, bool bDoLocationLag, bool bDoRotationLag,
                                                             float DeltaTime)
{
    TargetArmLength = BaseTargetArmLength + TargetArmLengthModifier;
	
Super::UpdateDesiredArmLocation(bDoTrace, bDoLocationLag, bDoRotationLag, DeltaTime);

	TargetArmLengthModifier = 0.0f;
}

FVector UHoatCameraSpringArmComponent::BlendLocations(const FVector & DesiredArmLocation, const FVector & TraceHitLocation, bool bHitSomething, float DeltaTime)
{
	// by default it returns bHitSomething ? TraceHitLocation : DesiredArmLocation
	FVector blendedLocation = Super::BlendLocations(DesiredArmLocation, TraceHitLocation, bHitSomething, DeltaTime);

	if ((GetComponentLocation() - blendedLocation).Size() < MinTargetLength)
	{
		// We should rotate around our pitch
		return PreviousDesiredLoc;
	}

	return blendedLocation;
}

Have you tried using breakpoints and stepping through it?

Yeah that’s why I can assure you that UpdateDesiredArmLocation() is called. :confused:

But next week I will download the debug symbols to be able to step inside the engine.