Multicast not firing

Hey guys!

I’ve got a small setup where player can apply a camo to their weapon. Since other clients need to see the Camo too, i’ve made a small multicast function that sets the players camo for that client, and all other clients:

void AChatSystemCharacter::SetWeaponCamo_Implementation(UMaterial * Mat)
{
GunMesh->SetMaterial(0, Mat);
}

Once a player picks up a camo paint, upon using it the following function is called:

//Called when the player uses the paint on their gun. Applies a camo to the gun
void AWeaponPaint::Use()
{

AChatSystemCharacter* Character = Cast<AChatSystemCharacter>(UGameplayStatics::GetPlayerCharacter(this, 0));

//This is a Multicast that sets and updates the players weapon material for the player and all other clients
Character->SetWeaponCamo(WeaponCamo);

//This just destroys the WeaponPaint actor after use
Super::Use();

}

The problem is that the WeaponCamo actor cannot call the Multicast function. It will be called on the local client, but won’t get called on the other clients too, which is what a Multicast is supposed to do.

Anyone know what is happening? I have a feeling it is due to Ownership, but not sure what the solution is here.

Thanks everyone!

So there are two common patterns to follow for multiplayer programming:

Have the client execute a Run At Server RPC to get from the Client to the Server. Then run a Multicast RPC on the server to replicate an event to all clients.

This method is good for temporal things. Things that happen, but then disappear, such as particle effects and animation montages.

The second pattern is to have the client execute a Run At Server RPC to get from the Client to the Server. Then have the Server change the value of a Rep Notify variable. Then when the variable value is replicated back to the Client, an OnRepNotify function is called on the client to allow you to change whatever it is you need to change on the client.

The second pattern is much better for permanent changes because unlike the multicast it will maintain state. I think in your case since you want the camo to stay set for more than just a few seconds,you probably want to go with the second pattern. From your code I can’t tell if you are missing the initial Run At Server RPC to get from the Client to the Server. If so, then that is probably why your multicast isn’t working. But even if you get it to appear like it is working with a Multicast, I have a feeling it will work intermittently until you switch to a Rep Notify variable instead.

If you have any questions about the difference between the two, take a look at this video on Network Relevancy that explains the difference between Multicast and Rep Notify:

Thanks for the info. Quick question - is a RepNotify executed on all clients like a NetMulticast?

Yes, RepNotify is executed on all clients that have the object.

Another thing you will want to look into for multiplayer programming is which objects exist on which clients. For example, every client has a copy of every Character object, but the PlayerController object is only on the client that owns it.