hi!
i’v had this problem more than i should so i thought i ask for help
i want to destroy an actor in multiplayer but it’s not working, at first i tried to make the input event in the actor blueprint but it doesn’t seem to be working in multiplayer … it least for me. so i made the input event in the player character (ThirdpersonBP) blueprint. I’v casted to my actor blueprint like this
it’s the only working way i found to cast lol.
and when the player presses F i want him to destroy the actor multicasting it to everyone:
then it runs this function in the actor blueprint :
to make sure the function gets called i made a print string and it seems to print the text to everyone. where is the problem ? the actor BP is replicated and i’m using UE4 4.9 in a dedicated server, thank you .
I didn’t use replication in UE4 so this is wild guess, but i think if you destroy actor on the server it should replicate destruction to client semlessly as server contains original state, so there no need to do it for as all clients. Alternativly problem might be with “The Actor Refrence” being none on clients,
Hi , as say, your actor need to be Replicated and you need to create the actor only on server. Then for destroy, the same thing, you need to destroy the actor on server. See the next image. Cheers
Note that both events (Create Actor Sample and Destroy Actor Sample) are Run on Server. Then you can call this events from a input action for example.
thank you and your answers were really helpful it worked for me but i have to press the input event twice … and is there another way of destroying it . thank you!
Hi , which input you press twice, the one that call the destroy event or the one that call the create event ? Anyway is weird, can you send me a screenshot of your blueprint please ?. Also, remember to mark as Replicated the actor that you what to create/destroy. Another way to destroy it is, also on server, set the LifeSpan property. This is useful if you want to destroy the actor after x seconds. Best regards
hey , i have to press the input event twice for the one to destroy the actor, and yes it’s replicated here’s a screenshot:
as you see i spawn the actor in the character blueprint is it ok? i do it to spawn it and get reference to “TheActor” blueprint and because i want it spawned when the game statrs.
and here’s the destroy function in “TheActor” blueprint:
thank you so much for you help
Hi , the problem that you have is because you are spawning the Actor inside the begin play of your Character. When you run you game with two instance this method run twice on server, because the server spawn your first character run the Begin Play and spawn the ActorTest. Then, join the second character and also on server is spawned another instance of the ActorTest. remember, each character is spawned on server and also, on server, the begin Play of each character is executed. Now you can see only one ActorTest because your are spawning in the same position, but the real thing is that in the same place are two instance of ActorTest.
Then, when you execute the destroy event, you destroy the first instance, but apparently nothing happen because you have in the same position the second instance, and you need to call the method again to destroy the second one. Test with three instance, for example, you will need to execute the Destroy method three times because you will have three instance of ActorTest.
You need to spawn you actor in another place ony one time, for example, in the Begin Play on your Level Blueprint (also with the Switch Has Authority). Then if you need to store the reference of this actor on each character to use before destroyed. On the Begin Play of your Character call Get All Actor of Class BP_ACtorTest and store the reference.
Then, for destroy, if you already have the reference you can simply call TheActorReference->Destroy always inside a Event that Run On Server.
If you dont have the reference, in the Destroy Event call first Get All Actor of class, and the DestroyActor.
Best regards.
Thank you so much you were so helpful <3.