If anyone has experience with destroying actors over multiplayer i’d really appreciate any help, as i’ve been tearing my hair out over this for a good week. Thanks a bunch!
Sorry for the late reply; I assume you meant the “Destroy” event in the gun bp? If so, then it still doesn’t work on the client but it still destroys the gun for the server.
The EquipPistol() function is not replicated but, the Server_EquipPistol() is, so you can use the same EquipPistol() function both on client and server side, without having to duplicate your code.
Regarding your actual issue, it might be a stupid question but do you have your Actor actually set to replicate?
In my last post I was suggesting that you probably don’t have to use a replicated function to destroy the Actor. If the Actor replicates, and it gets destroyed on the server, the clients should also auto-destroy them, without having to explicitly tell them. I might be wrong, but I would definitely try this.
I changed what you suggested and it’s still not working on the client. The gun actor has been replicating. Your logic should work and I’ve set up this system that way in one of my many attempts to solve this, but I believe at heart this issue is due to the replication of my gun reference variable set after spawning it. After the client tries to unequip the gun, I get an error saying it’s pending kill from this ( https://gyazo.com/6ba9066d90cdaa504fe118ad9105c998) macro
I am very confused looking at your graph. You do not need to spawn the pistol twice, only once, on the server. If the pistol is set to be replicated, it will be visible for the clients as well. Use a SwichHasAuthority node before you spawn your pistol and only spawn it on the Authority pin.
Double check if your pistol replicates, and only destroy it in a non-replicated OnAuthority guarded CustomEvent called for example DestroyPistol(). If you have an unequip animation, trigger a Multicast CustomEvent from the DestroyPistol() CustomEvent playing the animation etc, and set a Delay before actually destroying the pistol (in the DestroyPistol(), not in the Multicast event).
Yes, this is what I suggested, is this not working? Are you a 100% sure that your Pistol class replicates (not only the reference but the class itself)?
It looks like you are trying to access the PistolRef after the DestroyActor was called. PendingKill error usually means that the object has been garbage collected, but not completely removed from the memory yet (but unsafe to use).
It is generally a good practice the check if a reference is valid, before you are trying to use it. You can do this with the IsValid node. Only use references that return Valid and you should prevent the error from happening.
Right, I understand that much but adding isValid before would just mean that the actor doesn’t even try to be destroyed. This is why I think it’s an issue with the referenced gun being replicated as a variable
No, you get the PendingKill error, because you are trying to access the reference AFTER you have called destroy on it.
Locate each place where the PistolRef is used, and ensure that nothing is trying to access it after you have called the DestroyActor function.
EDIT: If you are not using it elsewhere, turn off the replication on the reference variable, as you do not need it to be replicated then!