Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Terrain Collider don´t work for clients after update to Netcode 1.4.0

Discussion in 'Netcode for GameObjects' started by TruckerJoe, Jun 4, 2023.

  1. TruckerJoe

    TruckerJoe

    Joined:
    Feb 25, 2019
    Posts:
    35
    I change my Unity Version from 2021.3.21f LTS to 2022.3.0f1 LTS, from Netcode 1.2.0 to 1.4.0 and now my clients are falling throu my terrain. The Host works fine.
    Did anyone have an idea what I can do?
     
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    426
    Hi @TruckerJoe , Terrain collider is not a feature that Netcode for GameObjects handles, so it's more likely that the issue is caused by the update to Unity 2022.
    If you revert to NGO 1.2.0, do you have the same issue?
     
  3. TruckerJoe

    TruckerJoe

    Joined:
    Feb 25, 2019
    Posts:
    35
    Thx @RikuTheFuffs-U for your answer.
    I also figured that the terrain had nothing to do with netcode, I only wrote it because it was the only 2 things that changed.
    The unity version and the netcode version.
    Can you tell me how to switch back to version 1.2.0? I can not find an option in the packet manager.
     
  4. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    426
    Sure, you can go to your project's folder, then Packages > manifest.json and change the version of NGO ( com.unity.netcode.gameobjects ) from there back to 1.2.0

    Remember to backup before doing so, as downgrading the package might cause issues.

    Does this help?
     
  5. TruckerJoe

    TruckerJoe

    Joined:
    Feb 25, 2019
    Posts:
    35
    Nope, downgrading to Version 1.2.0 didn´t help :-(
    I see now this warning:
    [Netcode] Deferred messages were received for a trigger of type OnSpawn with key 6, but that trigger was not received within within 1 second(s).
    I didn´t noticed this warning before the unity upgrade, but I am not sure.
    Could that be the reason?
     
  6. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    426
    It sounds like you could be running into an issue where you might be sending network messages (I.E: an RPC or NetworkVariable) before a client is fully synchronized.

    There are a few ways you can do this:
    Pre-Spawn Synchronization: This assures that any information you need to be available when a NetworkBehaviour's OnNetworkSpawn method is invoked gets set prior to it being invoked.

    The server always writes and clients always read during NetworkBehaviour.OnSynchronize.

    it's invoked whenever a NetworkObject is spawned (which also happens when a client first connects and is sychronizing), and assures there is no latency between the spawning and the applying of the data needed for the NetworkBehaviour in question.

    OnClientConnected: If you have scene management enabled, then this is invoked on the server and client side when the client is finished fully synchronizing (synchronization occurs upon the initial connection and approval of the connection).

    This too can be used to trigger a ClientRpc on the server side, but you would need to add the ClientRpcParams to the end of your ClientRpc method and only set the newly connected client id passed into your subscribed method callback.

    This will result in a latency of about a full RTT as the server has to wait for the client to send it the SceneEventTypes.SynchronizationComplete event before OnClientConnected is triggered and then the client has to wait for the ClientRpc from the server.


    The other way is to register for the NetworkSceneManager.SynchronizationComplete event on the server side and send it then, but both OnClientConnected and SynchronizationComplete are invoked at the same call stack location so they both result in the same latency.

    Maybe, but I doubt so. Did you already comapre the state of the terrain on the server and clients? Maybe you initialize it properly (I.E: enable colliders) only in one of the two. Doing a side-by-side inspector and layer comparison should help.

    Does this help?
     
  7. TruckerJoe

    TruckerJoe

    Joined:
    Feb 25, 2019
    Posts:
    35
    So I tested a lot, and found out that the terrain collider in the 2022LTS Version has more options in the inspector.
    "Provides Contacts" and "Layer Overrrides" are new.

    I have scene managment enabled, What should I make in the OnClientConnected? Did you mean that I then should spawn the player prefab?

    At the moment I spawn the player with a "Spawn Manager", it is a gameobject in the gamescene, and on the OnNetworkSpawn methode, it ask the server over a serverrpc to spawn the client player object.
    This worked fine in 2021LTS Version.

    I tested also in witch order the gameobjects are being called.
    On both versions it is like:
    terrain -> awake()
    spawnmanager -> spawn the player prefab
    terrain -> start()
    and in the 2022LTS I am under the terrain after spawning.

    I paused the editor while my player was falling down, and I put it with the tranform in the inspector above the terrain, and unpaused the editor. And the terrain collider is working fine, as expected.
    So it seems that only the moment where the client player gets spawned, the terrain collider doesn´t work correct.
     
  8. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    426
    it seems like a compenetration issue, can you try spawning the player a bit higher or with a delay?
     
  9. TruckerJoe

    TruckerJoe

    Joined:
    Feb 25, 2019
    Posts:
    35
    Spawning higher or with delay doesn´t work.
    But I found out something interesting.
    When the player is under the terrain collider, the player is at position (0,-something(falling down), 0), but I spawned the player at (94.5f, 10f, 50f)
    So not the terrain collider is that problem, the problem is that the server spawnes the player at 0,0,0.

    Here is my spawning code:
    Code (CSharp):
    1. [ServerRpc(RequireOwnership = false)] // Server owns this object but client can request a spawn
    2.     public void CreatePlayerServerRpc(ulong clientId, int prefabId)
    3.     {
    4.  
    5.         Vector3 testStartpoint = new Vector3(94.5f, 10f, 50f);
    6.         Debug.Log("Spawning player at:" + testStartpoint);
    7.         GameObject tempGo = null;
    8.         tempGo = (GameObject)Instantiate(player1, testStartpoint, Quaternion.identity);
    9.         Debug.Log("Position is:" + tempGo.transform.position);
    10.      
    11.         NetworkObject netObj = tempGo.GetComponent<NetworkObject>();
    12.         tempGo.SetActive(true);
    13.         netObj.SpawnAsPlayerObject(clientId, true);
    14.  
    15.     }
    The Debug.Log sais that he is at 94.5, 10, 50 after spawning, but in the game he is at 0,0,0 falling down.
    I also found out, that if I disable all the buildings in my level (there are alot) the spawning with terrain works without any problems.
    My player has Client Network Transform Script attached.
    In short:
    If I have my building active, the client player is at wrong position after spawning.
    Any ideas?
     
  10. TruckerJoe

    TruckerJoe

    Joined:
    Feb 25, 2019
    Posts:
    35
    I found the issue!
    If I set Interpolate to None at the Rigibody of the player, it worked as expected.
    In Unity 2021LTS with Netcode 1.2.0 I can set Interpolate to Interpolate and it worked.