Bind Default Pawn delegate to a GameMode's method

Hi!

I have a Character class which has a delegate. If I want to bind that delegate to the GameMode and Character class spawns automatically because it is set as Default Pawn. How can I do it?

Probably, I can do something like this:

MyDelegate.AddDynamic(this /* AMyGameMode */, &AMyGameMode::HandleCharacterEvent);

But I suppose the method `AMyGameMode::HandleCharacterEvent should be public. If the method must be protected or private, how can I do it?

Maybe I can get a reference for the instantiated Character.

Thanks

If I understand correctly, you can make the binding inside AGameModeBase::SpawnDefaultPawnFor_Implementation, or something like that…

Delegates are used for dependency reversal.

It becomes a responsibility of the Game Mode to bind to the character event. (as opposed to directly casting to your GameMode and calling its method from the pawn)

In your case you should probably just call some kind of a public Register method on your Game Mode (on possess of your character) and leave it to handle the rest inside.