Customizing Network Visibility

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!

After some dotPeek usage, it actually appears this is not possible. I hope I am wrong about this, though.

NetworkConnection.cs:

    internal void AddToVisList(NetworkIdentity uv)
    {
      this.m_VisList.Add(uv);
      NetworkServer.ShowForConnection(uv, this);
    }

    internal void RemoveFromVisList(NetworkIdentity uv, bool isDestroyed)
    {
      this.m_VisList.Remove(uv);
      if (isDestroyed)
        return;
      NetworkServer.HideForConnection(uv, this);
    }

NetworkServer.cs:

    internal static void ShowForConnection(NetworkIdentity uv, NetworkConnection conn)
    {
      if (!conn.isReady)
        return;
      NetworkServer.instance.SendSpawnMessage(uv, conn);
    }

    internal static void HideForConnection(NetworkIdentity uv, NetworkConnection conn)
    {
      conn.Send((short) 13, (MessageBase) new ObjectDestroyMessage()
      {
        netId = uv.netId
      });
    }

Anyone have ideas? It’s pretty bizarre that we cannot substitute this functionality.