Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Object Visibility with [NetworkProximityChecker]

Discussion in 'Multiplayer' started by Pelican_7, Jun 11, 2015.

  1. Pelican_7

    Pelican_7

    Joined:
    Nov 25, 2014
    Posts:
    190
    Hi all,

    I'm trying to implement object visibility (http://docs.unity3d.com/Manual/UNetVisibility.html) in my multiplayer game. I have placed a [NetworkProximityChecker] component on the objects I wish to be enabled/disabled based on distance. However, when this object is subsequently spawned on a client, Unity raises an ArgumentOutOfRangeException on my host. The full stack trace is included below.

    The object I am spawning has components [NetworkIdentity], [NetworkTransform], and [NetworkProximityChecker], as well as a [CapsuleCollider] for the distance testing.

    I am using Unity 5.1.0f3.

    Could this be a bug in Unity or is there something I should be aware of in my current setup?

    Thanks in advance,
    Andy

    ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: index
    System.Collections.Generic.List`1[UnityEngine.Networking.PlayerController].get_Item (Int32 index) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
    UnityEngine.Networking.NetworkProximityChecker.OnCheckObserver (UnityEngine.Networking.NetworkConnection newObserver) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkProximityChecker.cs:44)
    UnityEngine.Networking.NetworkIdentity.OnCheckObserver (UnityEngine.Networking.NetworkConnection conn) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:328)
    UnityEngine.Networking.NetworkServer.SetClientReadyInternal (UnityEngine.Networking.NetworkConnection conn) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:1119)
    UnityEngine.Networking.NetworkServer.SetClientReady (UnityEngine.Networking.NetworkConnection conn) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:1064)
    UnityEngine.Networking.NetworkManager.OnServerReady (UnityEngine.Networking.NetworkConnection conn) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkManager.cs:709)
    UnityEngine.Networking.NetworkManager.OnServerReadyMessageInternal (UnityEngine.Networking.NetworkMessage netMsg) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkManager.cs:600)
    UnityEngine.Networking.NetworkConnection.HandleMessage (System.Collections.Generic.Dictionary`2 handler, UnityEngine.Networking.NetworkReader reader, Int32 receivedSize, Int32 channelId) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:301)
    UnityEngine.Networking.NetworkServer.InternalUpdate () (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:652)
    UnityEngine.Networking.NetworkServer.Update () (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:514)
    UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:706)
     
    CarterG81 likes this.
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    Hm.. it looks like a bug. Could happen if there are no players for a connection. I'll file a bug on that.
     
    CarterG81 likes this.
  3. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    bug 703979 filed.

    To workaround this, use a script derived from NetworkProximityChecker:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3.  
    4. public class ProxChecker : NetworkProximityChecker {
    5.  
    6.     public override bool OnCheckObserver(NetworkConnection newObserver)
    7.     {
    8.         return false;
    9.     }
    10. }
    11.  
    But for now, players will no see objects until the object's visibility is updated. So could lag for a second after they log in.
     
  4. Pelican_7

    Pelican_7

    Joined:
    Nov 25, 2014
    Posts:
    190
    Great, thank you kindly for posting this seanr. I have got object visibility working now. And cheers for filing the bug too.

    I'm going to also override OnRebuildObservers to support child colliders on my player object.

    Thanks for your help, much appreciated.
    Andy
     
unityunity