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:
- Input causes the reliable multicast function to be called on the server
- The multicast function DOES run on the client
- Immediately after the multicast function is run on the client, some deeper engine code is run
- 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.