Search Unity

Customizing Network Visibility

Discussion in 'Multiplayer' started by cranky, Aug 2, 2018.

  1. cranky

    cranky

    Joined:
    Jun 11, 2014
    Posts:
    180
    Hi guys,

    I need to implement custom network visibility code in my game for a few reasons:

    1) enabling/disabling objects instead of spawning and destroying when network visibility changes
    2) send updated data about the object to a player when they begin observing it

    I can't use the built-in SyncVar or OnSerialize functions, as it does not fit my needs. Ideally, I'd like to send the data along with the packet which re-enables the object on the client.

    So far, I created my own Network Proximity Checker, but I cannot find the place where I can override the messages sent. According to the docs, an ObjectHide message is sent to destroy a no longer visible network object, and ObjectSpawn is sent to create it again. Where can I override this behavior and instead of sending ObjectSpawn, send a custom message? I couldn't find this information on Google or the docs.

    Thanks!
     
  2. cranky

    cranky

    Joined:
    Jun 11, 2014
    Posts:
    180
    After some dotPeek usage, it actually appears this is not possible. I hope I am wrong about this, though.

    NetworkConnection.cs:
    Code (CSharp):
    1.     internal void AddToVisList(NetworkIdentity uv)
    2.     {
    3.       this.m_VisList.Add(uv);
    4.       NetworkServer.ShowForConnection(uv, this);
    5.     }
    6.  
    7.     internal void RemoveFromVisList(NetworkIdentity uv, bool isDestroyed)
    8.     {
    9.       this.m_VisList.Remove(uv);
    10.       if (isDestroyed)
    11.         return;
    12.       NetworkServer.HideForConnection(uv, this);
    13.     }
    NetworkServer.cs:
    Code (CSharp):
    1.     internal static void ShowForConnection(NetworkIdentity uv, NetworkConnection conn)
    2.     {
    3.       if (!conn.isReady)
    4.         return;
    5.       NetworkServer.instance.SendSpawnMessage(uv, conn);
    6.     }
    7.  
    8.     internal static void HideForConnection(NetworkIdentity uv, NetworkConnection conn)
    9.     {
    10.       conn.Send((short) 13, (MessageBase) new ObjectDestroyMessage()
    11.       {
    12.         netId = uv.netId
    13.       });
    14.     }
    Anyone have ideas? It's pretty bizarre that we cannot substitute this functionality.