Search Unity

Network.Instantiate/Destroy security and limitations?

Discussion in 'Multiplayer' started by dnnkeeper, Oct 19, 2014.

  1. dnnkeeper

    dnnkeeper

    Joined:
    Jul 7, 2013
    Posts:
    84
    1) I've discovered recently that any player can call Network.Destroy to kill any network instantiated object: on server and on all other clients! How do I prevent this?

    2) Also I'd like to find a way to instantiate only actual objects (nearest to the player) instead of sending an avalanche of Network.Instantiate calls of every network object in the world to a newly connected player. I tried using custom RPC call as mentioned in the docs:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ExampleClass : MonoBehaviour {
    5.     public Transform cubePrefab;
    6.     void OnGUI() {
    7.         if (GUILayout.Button("SpawnBox")) {
    8.             NetworkViewID viewID = Network.AllocateViewID();
    9.             networkView.RPC("SpawnBox", RPCMode.AllBuffered, viewID, transform.position);
    10.         }
    11.     }
    12.     [RPC]
    13.     void SpawnBox(NetworkViewID viewID, Vector3 location) {
    14.         Transform clone;
    15.         clone = Instantiate(cubePrefab, location, Quaternion.identity) as Transform;
    16.         NetworkView nView;
    17.         nView = clone.GetComponent<NetworkView>();
    18.         nView.viewID = viewID;
    19.     }
    20. }
    21.  
    but I didn't manage to get OnSerializeNetworkView working this way. I'd be able to create a custom condition for sending buffered RPC and therefore make a scalable online world.

    Is changing networking library the only option? If so, I guess that such limitations should be mentioned in the docs.