How do i destroy a Actor in Multiplayer?
By Destroy, you mean kill? Should be the same as in Single Player by using the Destroy Node and pointing it to a target. Is there something else you are looking to do?
if i use the destroy actor node it doesnt destroy the actor for all clients…
You need to make it replicate to all clients. One way to do this is to create a custom event and then have it replicate the destroy.
Connection would be setup with your event replacing the current destroy node and then having your custom event fire off the destroy node.
I thought you meant in general, see DJ’s answer below you will need to make it replicate so that all clients receive the notice that the actor has been destroyed.
how do i replicate? Just call the event? So the event is sended to every cleint?
when you setup the custom event you will see a replication property for it. You can set it to multicast.
Perfect will try it! Thanks !
Okay i set it to multicast but it didnt work…
can you please put up your blueprint and also what is the base class
Did you find solution? I’ve got the same trouble.
I call normal event of actor, than call custom event On Server (for some logic calculations), than call Multicast custom event with two blocks: spawn Emitter at location and Destroy Actor (self).
Emitter spawning correct on server and client both, actor destroyed only on the server side.
Tried to change life span on run - the same effect - after time lag actor destroyed only on server side.
If I set up initial life span - actor correct destroys everywhere.
Actor got next replications properties set in True: Replicates, Replicate Movement, Always relevant.
I just solve my problem. Actually, the root of trouble was in actor spawning.
I spawn my replicated actor in normal mode, in this case client create his own copy of actor, and when I destroy on-server-created actor, client still have his own actor at the same position.
Solution: before spawn your actors ALWAYS put Switch Has Authority before it and use Authority branch to spawn actors. In that case client will have only replicated copy of actor, that will be destroyed correctly on multicast event.
I know this is old ( so this is mostly to others who might come by this post ) make sure you check the replicates on the actor you want to destroy
it’s under class defaults
Using the “Set lifespan” node seems to solve the issue.
If you are still stuck , I just solved a similar issue by making a custom event in the player controller,call it Server Destroy Actor, setting it to run on server, connect it to destroy actor, and off of destroy actor pass the actor reference to make a new pin on the custom event. Finally in the player character blueprint cast to the player controller and call Server Destroy Actor and hook up the actor. Good Luck! Cheers
thanks mate this thing works
@christoffer5700 's solution worked for me!
The proper way to destroy an actor in a multiplayer game (based on the engine code) is to call Destroy only server-side. For this method to work, you also need to make sure that your actor was spawned by the server and that the actor is set to replicate.
Thanks, I just did spawn actor with multicast I just change the server only and delete one to thanks for the advice.
Hey, don’t hesitate to upvote the answer if it helped you. As I believe previous answers are more “dirty fixes” than real solutions. Thanks.