- Home /
How can I delete or destroy an instance of an object IN A MULTIPLAYER GAME?.
How can I delete or destroy an instance of an object IN A MULTIPLAYER GAME?.
I know how to do this in a singleplayer game, but I need to know how to do this in a multiplayer game. What else I need?.
I can instantiate in the right way and I can watch in the server and client version...But the destruction is my problem: My rainbow can't be destroyed. :-(
My code is based on the tutorial called "M2H_Networking_Tutorial":
And my code is:
var rainbow:GameObject;
var rainbow_sound: AudioClip;
private var activate_rainbow:boolean=false;
var timer : float = 2;
function Awake () {
timer = Time.time;
}
function Update () {
//Called on the server only
if(Network.isServer)
{
if (global_counter.activate_rainbow==true)
{
var myNewTrans : Transform = Network.Instantiate(rainbow, transform.position, transform.rotation,0) as Transform;
global_counter.activate_rainbow=false;
//Get the networkview of this new transform
var newObjectsNetworkview : NetworkView = myNewTrans.networkView;
//Network.Destroy(myNewTrans,10);
if (Time.time - timer > 2)
{
Network.Destroy(gameObject);
}
}
}
}
Any suggestion?. Thank you in advance.
Answer by jorgon · Nov 07, 2011 at 10:29 AM
hi: I just have watched this in teh official manual reference:
Behind the scenes, Network Instantiate is simply a convenience function built around RPC calls. It serializes an identifier of the prefab that is to be instantiated, serializes all allocated NetworkViewID's, serializes the position, and send it across the network using an RPC call. Network.Instantiate() will always buffer the Instantiate call in the RPC buffer, this also means it can be removed from the buffer in the same way as other RPC calls. In essence this is a regular instantiation that is performed on all clients and automatically buffered. Players that join after the instantiation was performed will also receive the Instantiate call.
So, maybe I should remove all the buffered RPCs because internally Network.Instantiate works as a RPC sentence...What do you think about it?.
Thank you in adavance.
When I started using Unity Networking, I used Network.Instantiate for everything because it was convenient- until I realised where the harrowing bulletstorm I was putting new players through whenever they joined the game was co$$anonymous$$g from...
And how did you solve this?. What did you do with it?. Could you help me?. I'm not instantiating players...I'm instantiating objects.
Well, I stopped using Network.Instantiate. I ins$$anonymous$$d use a fairly complex web of RPC calls, which passes around NetworkViewIDs. I take advantage of the fact that once a NetworkViewID has been allocated by the Network, it doesn't have to get assigned to a networkView immediately- you can do that manually if you so choose. Look up Network.AllocateViewID in the reference, there's a good example of how to use it.
Please, could you copy any link to any tutorial?. I need to watch an example...
This is my actual state: http://forum.unity3d.com/threads/111237-How-to-destroy-objects-in-a-multiplayer-game?p=738454#post738454
Answer by jorgon · Nov 10, 2011 at 09:49 AM
The fact is that I can destroy an existing object but no an instanciated object...Or maybe the timers I use...Using timers for destroying objects use to be complicated...I don't know what can be my problem...