I spawn an actor on the server and then want it destroyed later. If the server does this, it works. If a client does this, it doesn’t destroy. In the World Outliner the Mesh_1 will briefly change to *(Deleted Actor) *but then reappear as *Mesh_2 *
I’m under the assumption that AStaticMeshActor is replicated (it shows up nicely on all the clients, so yeah) so I’m confused as to why this doesn’t work.
You shouldn’t be calling Destroy yourself (generally). Instead, just set the actor to invisible, disable it’s collision, and set “MyMesh” to null (I’m assuming that’s the UPROPERTY that is holding the reference to your instantiated mesh object). Garbage Collection will see no one is referencing the object anymore, and properly clean it up on both client/server.
You should always Spawn and Destroy a replicated Actor on the server. A client has no authority to destroy a server replicated Actor. It would be easy to cheat as a client if you could just Destroy any Actor the Server attempts to replicate.
I agree. When a client attempts to do it, you can see in the original code that it checks for authority and asks the server to perform the SpawnActor() and Destroy() functions.
(Edit: the .h file has the Server_ versions of those functions set to UFUNCTION(Server, Reliable))
Yeah its important to check if you are the owner, and also you can try this message passing route as well:
Client Sends Death RPC to Server() -> Server executes Death(check for owner) on Server() -> Server sends the Multicast for death to be called on each client()
I’m home now, so I’ve added the Owner to the FActorSpawnParameters, and logged it out to confirm, but it still won’t destroy (or hide and nullify) the AStaticMeshActor for the client players.
The log shows: LogTemp: Warning: I am: BP_MyCharacter_C_3 and MyMesh’s Owner is: BP_MyCharacter_C_3
I’m really struggling to understand what I’m missing.
When using Destroy() you can see the World Outliner switch to Actor Destroyed for a moment before replacing it with a new version, one number higher… As if the server was trying to re-sync its presence maybe? But I’m specifically telling the server to do the destroying.