Search Unity

Issues on develop branch

Discussion in 'Netcode for GameObjects' started by cerestorm, Dec 20, 2021.

  1. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    664
    I've switched over to develop branch to see if it sorts out some issues I'm having, and it's introduced a couple of new ones.

    On 1.0.0-pre.3 network objects with CheckObjectVisibility set to false correctly don't spawn on clients (at least not in my current projects but I've had issues elsewhere). In develop all network objects are spawned on clients regardless.

    On 1.0.0-pre.3 network objects spawned on clients are parented as per the server, in develop none are being spawned parented. AutoObjectParentSync is set on all network prefabs.
     
  2. CosmicStud

    CosmicStud

    Joined:
    Jun 13, 2017
    Posts:
    55
    Yes, I have seen this same issue. I think before the release 1.0, I implemented the delegates in the awake or at instantiation for pooling.

    The solution is implementing the network object's CheckObjectVisibility delegates just before calling the spawn method, I also implemented object pooling, but I do not think thats required.

    I do not know if this was intentional, because the updated docs doesn't show those changes. Hope that helps
     
    cerestorm likes this.
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    664
    Hmm I'm not object pooling but I am calling the delegate before spawning, here's the code I'm using.

    Code (CSharp):
    1.     public T SpawnPrefab<T>(bool visible) where T : NetworkBehaviour
    2.     {
    3.         T componentInstance = InstantiatePrefab<T>(visible);
    4.  
    5.         componentInstance.GetComponent<NetworkObject>().Spawn();
    6.         return componentInstance.GetComponent<T>();
    7.     }
    8.  
    9.     public T InstantiatePrefab<T>(bool visible)
    10.     {
    11.         string prefabName = typeof(T).Name + Constants.PREFAB_POSTFIX;
    12.  
    13.         GameObject prefabObject = (GameObject)Resources.Load(Constants.PREFAB_FOLDER + prefabName);
    14.  
    15.         if(prefabObject == null)
    16.         {
    17.             prefabObject = (GameObject)Resources.Load(Constants.PREFAB_NETWORK_FOLDER + prefabName);
    18.  
    19.             if(prefabObject == null)
    20.             {
    21.                 Debug.LogError("InstantiatePrefab: prefab not found: " + prefabName);
    22.             }
    23.         }
    24.  
    25.         GameObject gameObject = GameObject.Instantiate(prefabObject);
    26.         gameObject.GetComponent<NetworkObject>().CheckObjectVisibility = (clientId) => { return visible; };
    27.  
    28.         return gameObject.GetComponent<T>();
    29.     }
    Actually for some I do separate the Instantiate from the spawn call to set the values straight away, but I don't think parenting is happening for any objects, I'll have a play with it.
     
  4. CosmicStud

    CosmicStud

    Joined:
    Jun 13, 2017
    Posts:
    55
    Yeah, I tested as well, the latest develop branch breaks checkObjectVisibility, or at least my old implementation, I hope they are aware
     
  5. SamTheBay

    SamTheBay

    Joined:
    Jan 11, 2014
    Posts:
    14