- Home /
Network.Destroy doesn't remove objects on other systems?
When I network.Instantiate a mob on one computer, and another computer logs in, the object is where it should be. However, if that mob is destroyed with network.Destroy, and another computer logs in, the other computer still sees that mob.
What am I doing wrong?
(This is the important parts of the spawner code)
function OnNetworkLoadedLevel ()
{
yield;
yield;
yield;
if (!hasOne)
{
hasOne = true;
networkView.RPC("StartSpawningrpc", RPCMode.All);
}
else
Destroy(gameObject);
}
@RPC
function StartSpawningrpc ()
{
//Debug.Log("Made it here???");
for (var i = 0; i >= 0; i++)
{
yield WaitForSeconds (wait);
var i2= Random.Range(-30, 30)* range;
var j= 50;
var k= Random.Range(-30, 30);
var pos=Vector3(i2,j,k);
//Debug.Log("Made it here!");
if (amount < maxAmount)
{
amount++;
Network.Instantiate (enemy, pos, Quaternion.identity, 0);
}
}
}
Hey! the rpc group one looks pretty promising, but the documentary does not really tell what the ID int is all about. I have tried with this code:
Network.RemoveRPCsInGroup(networkView.viewID);
and a few others, but nothing seems to work. Any help?
Answer by ScroodgeM · Jul 30, 2012 at 07:32 PM
Network.Instantiate is buffered call Network.Destroy is not.
so, if you join the scene after instantiate-destroy was called, you got only instantiate call and see the object. just clear buffer after destroying for future joins
http://docs.unity3d.com/Documentation/ScriptReference/Network.RemoveRPCs.html http://docs.unity3d.com/Documentation/ScriptReference/Network.RemoveRPCsInGroup.html
Do remove the rpcs of the destroyed object? The reference says remove for a network player but it is not a player. Do I have to trick it into thinking the mob is a player somehow?
use group for object you want totally clean. this will not remove all the mobs rpcs from OTHER groups
So I have to change the group of one mob when it dies. How do I change the group?
Answer by Minchuilla · Apr 16, 2014 at 05:06 PM
For the purpose of more recent viewers:
To create a gameObject across the network use Network.Instantiate this includes a buffer so any client joining after the gameObject was instantiated will also have the gameObject instantiated.(note: this is in the form of a buffered RPC)
Network.Destroy destroys the gameObject on all players that are currently connected, however, this does not include a buffer. So a client joining after the deletion of the object will still have a copy of it.
To remove this copy use the code below:
Network.RemoveRPCs(networkView.viewID);
Network.Destroy(gameObject);
This code then removes the RPC to instantiate the gameObject for newer clients and then destroys the gameObject for all current users.
note: the gameObject does not need a networkView component attached to it for this to work.
Your answer
Follow this Question
Related Questions
How can I spawn a GameObject on all players in my multiplayer game? 0 Answers
Network.Instantiate is CHAOS. 1 Answer
Unity networking tutorial? 6 Answers
Players Not Showing 0 Answers
Multiplayer|3dText PlayerName 1 Answer