Multicast RPC Issue [Update 8/12]

Update by eXi 13.01.2016: I moved the problem to the Bug Report section to get someone from Epic to read this and share some knowledge. Main problem why i push this is:

“Reliable Multicast disconnects every other client than the Server and the Client on which actor it was called. I, for example, call this on a Component in my PlayerController and only the Client that owns the PlayerController survives this call. All other clients get killed or something :X”


I’m in the process of understanding how to program for multiplayer, and I’ve hit a strange bump. I’m doing a very simple RPC implementation in my PlayerController class:

void AMyPlayerController::ServerSetColor_Implementation()
{
	MulticastSetBarrel();
}

void AMyPlayerController::ServerSpawnBarrel_Implementation()
{
	if (GetWorld())
		GetWorld()->SpawnActor<ADynamicReplicatedStaticMesh>(FVector(0, 0, 500), FRotator(0, 0, 0));
		
}

void AMyPlayerController::MulticastSetBarrel_Implementation()
{
}

I’m running a listen server. Using DefaultPawn, default GameState, default HUD, and a custom PlayerController blueprint that extends from my custom PC class (which extends from PlayerController). The only things added from the default PlayerController class are the functions provided above. I have _validate functions set up but have not included them , except for the multicast function which doesn’t seem to require one.

ServerSpawnBarrel and ServerSetColor are called from blueprint input events in the PC blueprint. MulticastSetBarrel is not exposed to BPs. The ServerSpawnBarrel function runs without any issues. The issue arises when I call MulticastSetBarrel (called from ServerSetColor, which runs from an input event). If it is called from the server instance, all connected clients’ camera snaps to the center of the world and the screen goes black after a few seconds. If the multicast function is called from a client (via the client calling ServerSetColor), the calling client and the server are unaffected, but any other clients’ camera snaps to the center of the world and the screen turns black after a few seconds. Why would an empty multicast function cause such behavior?


UPDATE 7/15

To insure that there wasn’t some unknown thing in my project causing the issue, I created a new Basic Code project. The ONLY thing I changed in the generated code was adding this one multicast function to the PC.

UFUNCTION(BlueprintCallable, Reliable, NetMulticast, Category=Network)
void MulticastTest();

void ANetworkTestsPlayerController::MulticastTest_Implementation()
{
}

Calling this function from BPs on the server/listen client causes the same issue on all other connected clients. Am I just implementing multicast functions incorrectly or is this a bug with the engine?


UPDATE 7/16

I’ve downloaded the preview 4.3 build and the problem persists.


UPDATE 7/18

Setting the multicast function to Unreliable allows it to be called without killing the pawn (I assume that’s what’s happening?). However, I looked through the shootergame code and found a reliable netmulticast function, and I assume it works as it should. What’s the trick?


UPDATE 8/12

I’m still having issues with this, so I set a breakpoint in VS and stepped through a ton of code. The general sequence of events is as follows:

  1. Input causes the reliable multicast function to be called on the server
  2. The multicast function DOES run on the client
  3. Immediately after the multicast function is run on the client, some deeper engine code is run
  4. In 4.3.1, DataChannel.cpp, line 1550, ProcessBunch(), the following happens:
  • The Actor variable is for some reason NULL
  • This causes SpawnedNewActor to be set to TRUE
  • From what I can tell, this causes the PlayerController to be re-initialized, and BeginPlay() is called
  • After pressing Continue in VS to resume running the game, the client loses control and the screen goes black after a few seconds, suggesting that the PlayerController has been despawned

All of this simply because I called a reliable multicast function.

I’m having the same problem. In 4.2 at the moment.

Setting the multicast function to Unreliable allows it to be called without killing the pawn (I assume that’s what’s happening?). However, I looked through the shootergame code and found a reliable netmulticast function, and I assume it works as it should. What’s the trick?

I have now switched to 4.3 and the problem seems to be gone. Not sure what was wrong.

I downloaded the binary 4.3 through the launcher (I usually use source) and the problem still persists. Did you do anything different at all?

Hi,

Same problem , in 4.6 preview.

Cedric

Not a solution but a workaround.

I used instead a replicated variable with notification on replication (ReplicatedUsing = OnRepFunction).

You can create a dummy replicated variable for the occasion if needed. Changing the variable on the server will trigger the OnRepFunction on every clients.

Hi everyone,

I am having a similar issue right now and I might know the reason for this.
This issue happens in my weapon equip code. I am using a Multicast function to ensure the actor equips the right weapon on all machines (yes I know I could do that with a replicated variable with notification). On the Server everything runs fine, but on the client the weapon I am passing as an argument is NULL. My guess is that this happens because the weapon actor was not yet replicated to the client machine.
Why?
Well I doubt that the engine sends the whole actor everytime you pass an actor variable as an argument to a RPC. I did not look in the engine source code, but I would guess that instead an actor identifier is send over the network and once received the engine does a lookup, finds the appropriate actor and passes that actor to the implementation of the RPC. (Well I would implement it like that)

That would also confirm 's answer. He said to use a replicated variable with notification. But doing that he ensures that the function is only executed once it is guaranteed that the actor was replicated.

To summarize: The solution to this problem is to ensure all actors referenced in a RPC are replicated. I am going to test that out with my own implementation and see if I was correct.

I hope I managed to help someone with that answer.

Hi,

Have the same problem with reliable multicasts in 4.6.1. (black screen, position reset, blocked input from other gamepads, even “shift + F1 does not function”, etc…) Seems to be a bug. https://answers.unrealengine.com/questions/97569/client-cant-join-a-server-if-server-is-running-rel.html

The issue is that multicast rpc’s should never be reliable and if they are, should only be called when all connections have finished logging in. I posted an answer with greater detail and possible solutions .

Still having this issue when calling a “Reliable” multicast in a component that sits on my PlayerController.

Could someone from Epic explain us why this is happening?

Hello everyone,

This is very delayed but it seems that Timbo’s question got the attention of Dave Ratti who gave a very detailed response in the link above and seems to of fixed the issue. If anyone is still having this problem, please refer to the other post for more information.