A reference to a Blueprint Game Mode

I am new to Unreal Engine with a very basic knowledge of working with the blueprints and code together. I am having trouble with making a reference of my Blueprint Game Mode in the code.

The question is that i have a Game Mode Blueprint (BP_GameMode) and i need to make a reference of it in a class Flag something like this

BP_GameMode* TheGameMode = Cast<BP_GameMode>(GetWorld()->GetAuthGameMode());

Can anyone tell me how to do this? And i also wanted to ask that can i execute a custom event in my BP_GameMode like this??

TheGameMode->IncreamentScore(Amount);

Thanks in advance

The simple answer is you can not. your code does not know about BP, in fact it is compiled before it. The way to solve such a scenario is to create a base C++ class that your BP inherits from, that C++ class will then have a BlueprintImplementableEvent called IncrementScore which your BP game mode just implements.

The final code would like:

AMyBaseGameMode* TheGameMode = Cast<AMyBaseGameMode>(GetWorld()->GetAuthGameMode());
TheGameMode->IncrementScore(Amount);

Thanks for getting back but can you tell me how to make that BlueprintImplementableEvent ?

This would be an example:

UFUNCTION(BlueprintImplementableEvent, Category = "My Stuff")
void OnIncremenetScore(int32 Amount);

If you need a native implementation apart from the BP one you would have to use a BlueprintNativeEvent:

UFUNCTION(BlueprintNativeEvent, Category="My Stuff")
void IncremenetScore(int32 Amount);
virtual void IncremenetScore_Implementation(int32 Amount);

You would then add your native implementation in your .cpp like:

void UMyObject::IncremenetScore_Implementation(int32 Amount)
{
    // Increment you score in your native code
}

Thanks for that