Multicast not executing code on client?

I have a really simple setup:

PlayerPawn.h

UFUNCTION(Server, Reliable)
void AttackPiece_Server(AParentPiece* Attacker, AParentPiece* Defender);

  UFUNCTION(NetMulticast, Reliable)
  void AttackPiece_Multicast(AParentPiece* Attacker, AParentPiece* Defender);

PlayPawn.cpp (sorry, formatting isn’t working)

void AMatch_PlayerPawn::AttackPiece_Server_Implementation(AParentPiece* Attacker, AParentPiece* Defender)
{
if (IsValid(Attacker) && IsValid(Defender))
{
AttackPiece_Multicast(Attacker, Defender);

  UE_LOG(LogTemp, Error, TEXT("Called on server."));

}
}

void AMatch_PlayerPawn::AttackPiece_Multicast_Implementation(AParentPiece* Attacker, AParentPiece* Defender)
{
UE_LOG(LogTemp, Error, TEXT(“Called on client with %s.”), *this->GetName());

Camera->SetWorldLocation(FVector(0.0f, 0.0f, 1000.0f), false, nullptr, ETeleportType::None);
}

So I call a server function on the player pawn, which executes some server-only code. Then it calls a multicast function that’s supposed to call code that every client needs to execute.

It seems like it all works: “Called on server” prints at the right time, followed by a “Called on client with ___” for each player pawn. But all of the code I’ve tried executing after that UE Log in the multicast doesn’t work. The log gets called on every client, but subsequent code only gets called on the client that called the original server function. It’s as if I put a “IsLocallyControlled” gate right after the log, which I obviously didn’t.

The only thing I can think of is a problem replicating or accessing the player pawn? Even though the pawn successfully replicates across all clients, except for this one function now. Does anyone know what could be wrong?

Thanks in advance!

If the log is executed on each client then the rest of the code is executed too.
If the code doesn’t work, there’s an issue with your implementation of said code.
Maybe your Camera variable doesn’t point to what you expect?

1 Like

I’ve continued to mess around with it and every single function I’ve tried to call has failed to work, except for UE_LOG. I’ve tried moving the pawn, its camera, disabling input, and even just playing sounds. I’m really stumped now.

Update: I’ve decided to just use the game state’s player array to call client functions for each player individually. This has fixed the problem, though it’s not as elegant as I’d like it to be.

1 Like