Override C++ method in blueprint confusion

I am following this tutorial .So in my case I created 2 methods in the C++ class:

void ATC_LightSwitchBoth::OnOverlap_Implementation(class AActor* OtherActor, class UPrimitiveComponent* OtherComp,
	int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	if (OtherActor && (OtherActor != this) && OtherComp)
	{
		mPointLight1->SetVisibility(true);
	}
}

void ATC_LightSwitchBoth::OnEndOverlap_Implementation(class AActor* OtherActor, class UPrimitiveComponent* OtherComp,
	int32 OtherBodyIndex)
{

	if (OtherActor && (OtherActor != this) && OtherComp)
	{
		mPointLight1->SetVisibility(false);
	}

}

Now,I am not sure if I got it right from the tutorial,but my understanding was that suffixing the method with _Implementation means it is overridable by the blueprint inheriting from this class.I created a blueprint that inherits from LightSwitchBoth and added OnComponentEndOverlap event.But it doesn’t override the C++ event.It causes the light to become invisible which means it calls the default method anyway.So I probably missed the idea.Anyone can explain what’s going on here?May be _Implementation means the default C++ method does get called with the blueprint adding extension to it?

Sorry for the delay :smiley:

When implementing a method in a class via native code (C++ using the _implements function) or via a blueprint you are implementing the method for the given class. Like in any OO (Object Oriented) programming paradigm a class as one an unique implementation, the specialization comes from their inherited classes.

In your case I would suggest to create a child class in blueprint and override the method as a blueprint function, you also have to call the supers (the parent class) function which will be the C++ implementation.

As a working example I just created a new project using one of the templates, the sidescroller template in my case. I added a implementation of ‘CanJumpInternal_Implementation’ as shown in the following snippet:

class AMyNiceCharacter : public ACharacter
{
	GENERATED_UCLASS_BODY()


protected:

    // Overriden from ACharacter to provide double jump functionality
    virtual bool CanJumpInternal_Implementation() const override;
};

And then implemented the function in its cpp file:

bool AMyNiceCharacter ::CanJumpInternal_Implementation() const
{
    return Super::CanJumpInternal_Implementation();
}

Note the super call.

Now back in the editor I created a Blueprint inheriting from my class and I took the following steps to implement the event on the blueprint side too. Note that if I do not call the super function I will break the call chain.

17230-implements_1.png

The CanJumpInternal function is declared in the base character class (ACharacter) as:

UFUNCTION(BlueprintNativeEvent, Category="Pawn|Character|InternalEvents", meta=(FriendlyName="CanJump"))
bool CanJumpInternal() const;

Cheers,
Moss

But that’s what I am doing.I am extending the class via BluePrint.How do I override that method in blueprint?By creating new method with the same name via “new function” ?Also what is the difference then if I drop _Implementation suffix?

That’s what I did.See this tutorial: CPP and Blueprints Example | Unreal Engine Documentation

In order to make a method which is both defined in your class AND capable of being overridden from a blueprint, you need to declare its UFUNCTION as BlueprintNativeEvent. See https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Functions/Specifiers/BlueprintNativeEvent/index.html for details. Note that the declaration doesn’t have the _Implementation suffix, but the function definition (in the source file) does.

I’ve updated the answer with a small test that I just did.

Do you still need further assistance on this issue?