- Home /
Tell if remote Network.Instantiate object still exists
Is there a way to tell if the remote instance of a Network.Instantiate object still exists (or not)? I want to delete a remote instance locally, and then later call Network.Destroy without an error.
I am making a (2D) game where players can shoot bullets at each other. I'm using Network.Instantiate for the bullets so that I can destroy all its remote copies when the creator decides.
For the remote instances, I want the bullets to look like they're behaving normally, but only the creator can destroy the bullet and choose to inflict damage on players. (I understand this is not a secure method, but it's just for a prototype and I hear Unity's networking isn't secure anyway.)
SO! If a remote bullet thinks it hit a player, but the creator doesn't think it's hit yet, I want to destroy the remote instance locally. Later, on the frame the creator thinks the bullet "really" hit, I want to Network.Destroy the bullet. But this throws an error: Couldn't perform remote Network.Destroy because the network view 'AllocatedID: 51' could not be located.
There may very well be no way to do this. If so, what's the "right" implementation to handle this case? I guess I could hide the bullet on the remote side and set its script inactive, and then let it be destroyed when the creator copy says so?
Answer by Louis Watson · Sep 28, 2014 at 11:35 PM
well could you use SetActive on the bullet's gameobject to false then your destroy will not throw an error.
Actually if the remote object is inactive you get the same error. It's deactivating the networkView as well, I suppose.
my bad obviously the NetworkView must be perfor$$anonymous$$g an "Active" or "Enabled" filter when searching for items in the scene.
As a possible solution and without testing any code another option I could see is maybe tracking the ID's rather than the game objects themselves, then in the procedure that performs the Network.Destroy, you could perform a check on that id to see if its active before destroying it.
Alternatively wrapping the bullet in another Game Object could work. Disable the actual bullet when you want, then destroy the wrapper with Network.Destroy.
Your answer
Follow this Question
Related Questions
Network.instantiate & RPC destroy 3 Answers
How can I delete or destroy an instance of an object IN A MULTIPLAYER GAME?. 2 Answers
Checking if RPC queue is empty? 0 Answers
How to let the other network player to see a launched rocket and its explosion? 1 Answer
Player not deleting on server exit 1 Answer