I am seeing some inconsistencies in my project related to destruction of replicated actors.
In order to aid with debugging whether or not the actor is being destroyed on the client and server, I added some print functions to the blueprint as follows:
I am getting different results as follows:
Case 1: Server calls SetLifespan(0.01) to immediately destroy the actor. This is all done in C++.
if (HasAuthority()) {
creep->OnThroneReached();
CheckGameOver();
}
void ACreep::OnThroneReached() {
RewardIncome();
SetLifeSpan(0.01f);
}
The result from the print statements is:
Case 2: Creeps are killed and DeathMulticast is called to notify everyone of the units impending doom. The implementation of this multicast is to simply call a blueprint event, allowing blueprint to do some visuals and set the lifespan.
UFUNCTION(Reliable, NetMulticast)
void DeathMulticast();
void ATowerWarCharacter::DeathMulticast_Implementation() {
PlayDeath();
}
UFUNCTION(BlueprintNativeEvent, Category = "TowerWarCharacter")
void PlayDeath();
The logic in the blueprint is
This is where we start to run into problems. The server successfully destroys the unit, but the client never does.
I was able to make a workaround to this issue by forcing both the client and the server to call destroy directly in blueprint.
This then results in an interesting behavior where it appears that the server drops the connection and hands the client authority over the actor. I’m unable to attach another image of this, but the result is:
Server: Server Destroyed
Server: Server Destroyed
Server: Server Destroyed
Server: Server Destroyed
and
Client 1: Server Destroyed
Client 1: Server Destroyed
Client 1: Server Destroyed
Client 1: Server Destroyed
I am somewhat at a loss as to why the behavior for actor destruction is behaving so differently between these cases. Any help is greatly appreciated!