Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug ClientNetworkTransform resets the rotation (but not position) when spawned with ownership

Discussion in 'Netcode for GameObjects' started by neviovalsa, Dec 4, 2023.

  1. neviovalsa

    neviovalsa

    Joined:
    Jun 24, 2019
    Posts:
    33
    On the server, I want to instantiate some characters in specific positions and rotation before spawning them (with client ownership)

    I'm using the ClientNetworkTransform as shown here: https://docs-multiplayer.unity3d.co...ts/networktransform/#owner-authoritative-mode

    Code (CSharp):
    1.         private void SetupUnits(GameObject playerObject, ulong clientId)
    2.         {
    3.           ...
    4.                 // Select a random available spawn point
    5.                 Transform transform = _level.UnitSpawnLocations.spawnLocations.GetRandomAvailable();
    6.  
    7.                 GameObject unit = Instantiate(_unitPrefab, transform.position, transform.rotation);
    8.  
    9.                 // Spawn Unit
    10.                 unit.GetComponent<NetworkObject>().SpawnWithOwnership(clientId, true);
    11.                 //unit.transform.parent = playerObject.transform;
    12. ...
    13.             }
    14.         }
    The NetworkObject is spawned at the right position, but the rotation gets reset.

    I'm not sure if it would be excpected behaviour, as once spawned only the client can write the transform, but why would the position be synched then?
     
  2. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    244
    Could you take an inspector view screenshot of the network prefab's assigned (client) NetworkTransform?
    Just want to see all of the settings prior to making any suggestions to resolve your issue.
     
  3. neviovalsa

    neviovalsa

    Joined:
    Jun 24, 2019
    Posts:
    33
    Sure, here it is:
    upload_2023-12-4_18-24-50.png

    (I'm not interested in X and Z rotation)
     

    Attached Files:

  4. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    244
    Hmmm... this could be a bug.
    Could you do the following to see if this resolves your issue?
    1. Copy your Packages\manifest.json file or save the com.unity.netcode.gameobjects entry value (text file or the like)
    2. replace your project's Packages\manifest.json com.unity.netcode.gameobjects entry with this:
      1. Code (CSharp):
        1. "com.unity.netcode.gameobjects": "https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git?path=com.unity.netcode.gameobjects#develop",
    Let me know if the issue persists or no longer happens with the current pending v1.8.0 NGO updates?
     
  5. neviovalsa

    neviovalsa

    Joined:
    Jun 24, 2019
    Posts:
    33
    Thanks for the suggestion but unfortunately it doesn't seem to make a difference.
     
  6. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    244
    Here is a project that provides you with a recommended way to handle spawn points and assignment of position and rotation when using an owner authoritative model (i.e. client ownership). Let me know if this helps you resolve your issues with rotation not being correct upon a player spawning.
     

    Attached Files: