Proper way to destroy replicated Actor?

If you destroy a replicated actor on the server it should automatically be destroyed on every client. Can you show some screenshots of your code?

Can anyone in here explain how to properly destroy a replicated object?

For instance, if I have a replicated Actor blueprint and I want to destroy the Actor while running an internal function, can’t I just use a run-on-server RPC and Destroy Actor in the event?

When I try this, it doesn’t work. It also doesn’t work if I try with multicast (thinking maybe it’s only getting destroyed on server but not on clients). Is there something basic I’m missing? Do I need to call into game mode? (that didn’t seem to work either)

This would be a server owned Actor with a function triggered by a pawn overlapping. The function definitely runs, but Destroy Actor doesn’t destroy actor.

Specifically, the functionality is “reduce health on the Actor, if it gets to less than 0, destroy it”. Health is verifiably 0, as far as I can tell “Destroy Actor” should run, but no errors are displayed and the actor is not destroyed. What gives?

Yes, please see attached. First image is the “die” function which plays some explosions and then destroys the actor (the explosions play, the actor does not destroy). The second is of the “laser hit” function where a laser overlaps the object and triggers and adjustment to health (and possibly a call to “die”). The actor and all variables concerned (except HUD, which is kept dumb) are replicated.

Wait are you getting the value, to check if the player should die or not, from a widget?

First thing, widgets are local, so even if you are feeding it the replicated data from your player it might not have the correct data when you do that check, why risk it? Why not get it directly from the player?

Secondly, why are you calling a multicast inside a multicast? Multicast functions only work when they are called inside the server. Even if your first multicast (MulticastOverlapEvent) is called in the server, every client will receive the order to execute it and so then every client will try to execute your Die multicast which will not work since it isn’t being called inside the server in the first place. Besides that, multicast RPCs should preferably be used only for aesthetic utility and not heavy gameplay logic, like a collision or dying.

So there might be multiple problems here. One of them is that your Die function is not getting to all clients since it is inside another multicast. The other problem is that your Health Val Percent variable doesn’t even has the correct value so it is failing the condition.

Edit: Can you show the code for the overlap event too please? The actual BeginOverlap node that calls your multicast overlap

Hey, thanks for your reply. I’m attaching a screenshot of what ended up working.

As you suggest, there were a few things wrong. I think what may have been messing me up is the HUD is a 3d hud on the AICore object, so changes to that end up needing to be multicast, while the actor destruction only needs to happen on the server.

2 multicasts in a row is silly, you’re right.

Anyway, thanks again!