NetMulticast function only called on server, not clients

I am trying to get multiplayer working where the player can attach equipment. The problem is that the code only seems to be running on the server, not the replicated actors. Here is the code:

.h



        UFUNCTION(Reliable, NetMulticast, WithValidation)
	void NetAttachEquipmentToSocket(const FString&  SocketName);
	virtual void NetAttachEquipmentToSocket_Implementation(const FString&  SocketName);
	virtual bool NetAttachEquipmentToSocket_Validate( const FString&  SocketName);


.cpp




void APlayerPawnCombat::AttachEquipmentToSocket(TSubclassOf<UEquipmentComponent> EquipmentToAttach, const FString&  SocketName)
{
	GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString("Called attach to socket! : ") + FString::FromInt(Role) + FString(" : ") + GetName());
	NetAttachEquipmentToSocket_Implementation( SocketName);
}

void APlayerPawnCombat::NetAttachEquipmentToSocket_Implementation( const FString&  SocketName)
{
	GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString("Called NETattach to socket! : ") + FString::FromInt(Role) + FString(" : ") +GetName());

}

bool APlayerPawnCombat::NetAttachEquipmentToSocket_Validate(const FString&  SocketName) { return true; }



When I run it, I only get a single message with Role == ROLE_Authority, so it seems the code is only being called on the server.

The odd thing is that I use a similar way to destroy all copies of an actor in another class, which seems to work:

.h



        UFUNCTION(NetMulticast, Reliable)
	virtual void DestroyAllCopies();
	virtual bool DestroyAllCopies_Validate();
	virtual void DestroyAllCopies_Implementation();


.cpp



void APickup::DestroyAllCopies_Implementation()
{
	GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString("Destroying! : ") + FString::FromInt(Role) + FString(" : ") + GetName());

	Destroy();
}

bool APickup::DestroyAllCopies_Validate() { return true; }


When this code executes I get three messages (one for the dedicated server, and one each for the 2 connected clients). Can anyone see why the first code isn’t working as expected?

Never mind, found it!

I was calling NetAttachEquipmentToSocket**_Implementation**, rather than NetAttachEquipmentToSocket. Oops!

1 Like