Get DefaultPawn instance in GameMode method

Hi!

I have a Character class with this delegate:

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnDied, AActor*, DiedActor, AActor*, InstigatorActor);

// …

public:

   UPROPERTY(BlueprintAssignable)
   FOnDied OnDied;

This Character class is the DefaultPawn for a Game Mode:

imagen

I want to bind the Character’s delegate to a private GameMode’s method in the GameMode.

How can I do it? or Where can I do it?

Because I need to get the instance of the DefaultPawn, but I don’t know how to do it, and also, where to do it.

Thanks!

In YourGamemode.cpp, e.g. BeginPlay():

MyCharacterClass* MyCharacter = static_cast<MyCharacterClass*>(UGameplayStatics::GetPlayerCharacter(GetWorld(),0));

MyCharacter->OnDied.Add(/*..*/)

don’t disagree with the above but i think a better idea it to have the Actor ‘Regsiter’ with the GameMode just in case the Character doesnt exist when the GameMode fires or if you choose in future to add other actors to the delegate.

Also you could have the GM spawn the Character instead of using the default pawn and then you have access to it and control over load order.