GetAuthGameMode returns nullptr

Hi All,

I am trying to create a multiplayer game which has Sword attacks. The Sword is a separate class that has a BoxComponent. I added a function on the BeginOverlap of the Sword on the server as below

In the OnSwordOverlap method, I tried applying damage using UGameplayStatics::ApplyDamage and AActor::TakeDamage (not together)

In the Character Class, I am binding a method to OnTakeAnyDamage as below
image

Inside the ReceiveDamage I am trying to access the GameMode using

GetWorld()->GetAuthGameMode()

but this returns nullptr when the character is swinging the weapon and the Overlap event occurs.

Edit: The sword overlap and the damage works fine when not swinging (default position)

Any Idea on how to approach this?

I really don’t know what could cause it, as actors are created after GameMode. But, what you can do is just save reference to the game mode in the BegingPlay(). Just create class variable, store it there, and do whatever needs to be done :slight_smile:

Btw. I see you use HasAuthority(). Is this online game? Don’t use GameMode for that. use GameState. GameMode is not valid for client.

Hi Bojann,

Thanks for your reply. Will give that a try and let you know.

And I am trying to access the GameMode only in the server instance and not in Client (Trying to create a dedicated server build for this game)