Search Unity

Client does not spawn.

Discussion in 'Netcode for GameObjects' started by lllllllllll, Nov 30, 2022.

  1. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    Hello,

    Sorry for the poor English.

    I'm using Steamworks.NET and SteamNetworkingTransport to create a multiplayer game.
    Stemworks.NET: https://steamworks.github.io/
    SteamNetworkingTransport: https://github.com/Unity-Technologi...m.community.netcode.transport.steamnetworking

    When a client connects to the host, two player prefabs are created on the host screen, but no player prefabs are generated on the client screen.

    Also, the following error is sent to the client side:
    [Netcode] Deferred messages were received for a trigger of type OnSpawn with key 3, but that trigger was not received within within 1 second(s).

    Anyone know the cause and how to fix it?

    Thank you.
     
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi! it seems an issue similar to the one in this post. Maybe the information there can help you?
     
  3. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    thank you for your reply.

    I have checked that post, but it seems different from my problem.
    In my case, the Player Prefab is not spawn on the client side.

    Maybe there is a problem with the SteamNetworkingTransport I'm using, so I'm investigating it, but I'm not good enough to solve the problem.
     
  4. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    When you say this, do you mean that when the client connects 2 new players are instantiated in that moment, or do you refer to the total number of players visible on the screen? (1 of the host, 1 of the client?)

    Also, did you set the Player prefab in the NetworkManager's prefab?
     
  5. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    Sorry for my lack of explanation.

    When the host starts the game, the host's Player Prefab is instantiated, and when the client connects to the host, the client is instantiated on the host's screen.
    However, neither the host nor itself is instantiated on the client side.


    I have confirmed that the PlayerPrefab has been set to NetworkManager.
     
  6. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    1. Does the PlayerPrefab also have the `NetworkObject` component?
    2. Can you try creating an empty player prefab with just a cube, and spawn it as the player to see if the issue reproduces? It might be caused by some scripts on your Player's object
     
  7. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    Thank you for your support.

    1. Yes, PlayerPrefab has NetworkObject Component.
    2. I try PlayerPrefab with just a cube(add NetworkObject).
     However, the problem remained largely the same. PlayerPrefab still spawn only on the host side.
     Mostly, I mean the error message is gone.
     [Netcode] Deferred messages were received for a trigger of type OnSpawn with key 3, but that trigger was not received within within 1 second(s).

    By the way, I got the following error on the host side. Any hints for solving the problem?
    Exception: GetSceneOriginHandle called when SceneOriginHandle is still zero but the NetworkObject is already spawned!

     
  8. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Thank you for your answers!

    What NGO version are you using? You could try updating to the most recent one (1.1.0)
     
  9. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    NGO version was using 1.0.1.
    I just updated to 1.1.0 and tried again, but the result was the same.
     
  10. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    I found myself struggling with this problem for about a week. lol

    Is it possible that this issue relies on a custom transport?
    In that case, I'm thinking of changing the game's network from the ground up. . .
     
  11. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    it could be, does the error appear if you use the default Unity transport?
     
  12. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    thank you so much for your long time support.

    I tried using UnityTransport, but the result did not change.
    The host and client PlayerPrefabs are instantiated on the host side, but neither is instantiated on the client side.

    NetworkManager.Singleton.StartClient()
    I'm doing the above inside Start(), could this be the problem?
    I'm wondering if it's a problem that the NetworkManager specification calls StartClient() at the beginning of the Scene.

    Actually, at the beginning of development, the HUD was displayed at the beginning of the Scene, and the implementation was to select the host and client from there. it was working fine.
    This problem occurred after removing the HUD and implementing an implementation that automatically determines the host and client after the scene changes.
     
    Last edited: Dec 2, 2022
  13. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    It could be. If you're doing this at start, when do you start the Host/Server?

    it's probably a timing problem then. You can try adding a coroutine to connect a few seconds later. I wonder if there's anything you could wait for instead (I.E: an event...)
     
  14. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    Host/Client: At scene start
    But the host starts the scene first. The client starts the scene after a delay.

    I started the StartClient() with a delay of 100 frames from the beginning of the scene, but the result was the same:(

    I can't think of any other reason. . .
     
  15. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    100 frames is a very little amount, and machine-dependent. I'd recommend waiting for a 5+ seconds (for testing purposes)
     
  16. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    I tried StartClient() 10 seconds after the scene started, but the result was the same.

    I noticed that NetworkManager is multiple instantiated. A Google search seems to show that the same issue is happening to different people. I'm not sure if this is the reason why the PlayerPrefab is not instantiated on the client side, but it's possible and I'll look into it.
     
  17. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    Umm...
    The problem of multiple instances of NetworkManager being instantiated has been resolved. This is simply because the scene where the NetworkManager is placed was loaded every time a SteamAPI callback came.

    I tried with a single NetworkManager, but the result was the same.
     
  18. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    1. You should definitely have only 1 NetworkManager
    2. Can you try re-implementing the UI selection? If it solves the issue, then there's probably a timing problem somewhere in your own code
     
  19. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    1. I tried only 1 NetworkManager.
    2.I will try it later.
    I found an error that might help. It seems to be happening inside StartHost().

    NullReferenceException: Object reference not set to an instance of an object
    Unity.Netcode.NetworkBehaviour.InitializeVariables () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkBehaviour.cs:607)
    Unity.Netcode.NetworkBehaviour.InternalOnNetworkSpawn () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkBehaviour.cs:465)
    Unity.Netcode.NetworkObject.InvokeBehaviourNetworkSpawn () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkObject.cs:914)
    Unity.Netcode.NetworkSpawnManager.SpawnNetworkObjectLocallyCommon (Unity.Netcode.NetworkObject networkObject, System.UInt64 networkId, System.Boolean sceneObject, System.Boolean playerObject, System.UInt64 ownerClientId, System.Boolean destroyWithScene) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Spawning/NetworkSpawnManager.cs:587)
    Unity.Netcode.NetworkSpawnManager.SpawnNetworkObjectLocally (Unity.Netcode.NetworkObject networkObject, System.UInt64 networkId, System.Boolean sceneObject, System.Boolean playerObject, System.UInt64 ownerClientId, System.Boolean destroyWithScene) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Spawning/NetworkSpawnManager.cs:489)
    Unity.Netcode.NetworkSpawnManager.ServerSpawnSceneObjectsOnStartSweep () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Spawning/NetworkSpawnManager.cs:755)
    Unity.Netcode.NetworkManager.StartHost () (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1182)
    GameManager.StartHost () (at Assets/GameManager.cs:57)
    GameManager.Start () (at Assets/GameManager.cs:33)
     
  20. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    It seems that the above error is the cause.
    However, the cause is unknown.
    I tried it with a simple scene with exactly the same NetworkManager and GameManager and it works fine. The PlayerPrefab uses exactly the same.
    Do you know the reason?
     
  21. lllllllllll

    lllllllllll

    Joined:
    Apr 10, 2016
    Posts:
    13
    After a week of fighting, I finally found the cause of all the evils!

    The NetworkObject set to this GameObject seems to be the cause of everything.
    If I remove the NetworkObject it works fine.
    However, this GameObject must have a NetworkObject. What should I do?


    It worked fine even with Key(Script) disabled. Is there any reason?
    Code (CSharp):
    1. using Unity.Netcode;
    2.  
    3. public class Key : NetworkBehaviour
    4. {
    5.     public string Name = "keyName";
    6.     public int KeyId = -1;
    7.  
    8.     public Key(string name, int keyId)
    9.     {
    10.         Name = name;
    11.         KeyId = keyId;
    12.     }
    13.  
    14.     public void Set(Key key)
    15.     {
    16.         Name = key.Name;
    17.         KeyId = key.KeyId;
    18.     }
    19.  
    20.     public void Set(string name, int keyId)
    21.     {
    22.         Name = name;
    23.         KeyId = keyId;
    24.     }
    25.  
    26.     public void DestroyKey()
    27.     {
    28.         DestroyImmediate(this.gameObject);
    29.     }
    30.  
    31.     [ServerRpc(RequireOwnership = false)]
    32.     public void DestroyKeyServerRpc()
    33.     {
    34.         this.GetComponent<NetworkObject>().Despawn(true);
    35.     }
    36.    
    Also, I didn't do anything with this GameObject at the time this error occurred.
    Just being in the scene will cause an error.
     

    Attached Files:

    • key.png
      key.png
      File size:
      59.3 KB
      Views:
      107
    Last edited: Dec 3, 2022
  22. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    The DestroyImmediate at line 28 seems pretty dangerous. You should use Destroy instead.
    Maybe you're also calling DestroyKeyServerRpc or DestroyKey at the wrong time?
     
  23. Johannes_Jonas

    Johannes_Jonas

    Joined:
    Apr 25, 2023
    Posts:
    1
    I had a similar problem were there are spawning players at the host but not at the client side, but with a different Exception.
    Exception: Scene '' couldn't be loaded because it has not been added to the build settings scenes in build list.
    Unity.Netcode.NetworkSceneManager.SceneHashFromNameOrPath (System.String sceneNameOrPath)


    But my scene was added in the build settings so I found I work around by disabling the Scene Manager in the NetworkManager. This works for now...
     
    Omega53 and nubick like this.
  24. nubick

    nubick

    Joined:
    Nov 17, 2012
    Posts:
    30
    This helped me in the same case issue when player prefab doesn't spawn on client.
     
  25. Omega53

    Omega53

    Joined:
    Nov 28, 2018
    Posts:
    3
    Yeah as of April 2024 seems like this issue still persists... disabling the Scene management tick did the work. Many Thanks!
     
  26. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    258
    If this is the root of the issue then you can resolve this by increasing your NetworkManager.NerworkConfig.SpawnTimeout value (Spawn Timeout if scene management is enabled).

    Legacy versions had this value set to 1 second which would mean it could drop spawn messages during the initial scene synchronization. If you started your project with an earlier version of NGO (i.e. v1.6 or earlier) then most likely it is set to only hold messages for 1 second before discarding them.

    The more recent default timeout is 10 seconds.