Search Unity

Bug Spawning certain prefabs before second client joined, cant connect to that scene

Discussion in 'Netcode for GameObjects' started by GengarGames777, May 19, 2023.

  1. GengarGames777

    GengarGames777

    Joined:
    Jul 8, 2017
    Posts:
    16
    Hey, been trying to figure out go netcode
    now i'm struggling connecting with the second client as of a sudden.
    I fixed this earlier today by removing and re-adding a networkobject script on one of the spawned prefabs.

    So what happens is : two players, one is host and one is client
    host starts game (using relay if thats important) and loads the main scene via the network scene manager.
    Client joins via join code and that used to work, but only if i dont spawn said prefabs before the client joins.
    He can see them and they work fine if i spawn them after he joined.
    It works with another set of prefabs, which also get spawned once the host is in that scene.


    Now that does not seem to help, besides the warning (yea not error) is not really much of help:
    nc.png

    Here the full text:

    Code (CSharp):
    1. Trying to receive TimeSyncMessage from client 0 which is not in a connected state.
    2. UnityEngine.Debug:LogWarning (object)
    3. Unity.Netcode.MessagingSystem:GetMessageVersion (System.Type,ulong,bool) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.3.1/Runtime/Messaging/MessagingSystem.cs:504)
    4. Unity.Netcode.MessagingSystem:ReceiveMessage<Unity.Netcode.TimeSyncMessage> (Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkContext&,Unity.Netcode.MessagingSystem) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.3.1/Runtime/Messaging/MessagingSystem.cs:530)
    5. Unity.Netcode.MessagingSystem:HandleMessage (Unity.Netcode.MessageHeader&,Unity.Netcode.FastBufferReader,ulong,single,int) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.3.1/Runtime/Messaging/MessagingSystem.cs:416)
    6. Unity.Netcode.MessagingSystem:ProcessIncomingMessageQueue () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.3.1/Runtime/Messaging/MessagingSystem.cs:436)
    7. Unity.Netcode.NetworkManager:OnNetworkEarlyUpdate () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.3.1/Runtime/Core/NetworkManager.cs:1397)
    8. Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.3.1/Runtime/Core/NetworkManager.cs:1329)
    9. Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.3.1/Runtime/Core/NetworkUpdateLoop.cs:185)
    10. Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.3.1/Runtime/Core/NetworkUpdateLoop.cs:208)
    11.  

    Edit:
    im using 1.3.1 btw and 2022.2.17

    i tried 1.4.0 but its same
    i also tried 1.1.0 which does not give any warning at all
     
    Last edited: May 19, 2023
  2. GengarGames777

    GengarGames777

    Joined:
    Jul 8, 2017
    Posts:
    16
    Its not actually the prefab it seems but the amount.

    This code works and both can play on that scene but if i set the x < 11 to x < 12 , it stops working and gives the warning as before.

    Code (CSharp):
    1. public override void OnNetworkSpawn()
    2.     {
    3.         base.OnNetworkSpawn();
    4.  
    5.         if (IsServer)
    6.         {
    7.             for (int x = 0; x < 11; x++)
    8.             {
    9.                 GameObject go = Instantiate(plantsPrefab,
    10.                     plantsParent.transform.position + new Vector3(x + 1, 0, 3),
    11.                     Quaternion.identity, plantsParent.transform);
    12.                 go.GetComponent<NetworkObject>().Spawn();
    13.             }
    14.         }
    15.     }
    I can keep spawning enemies after both joined, added like 20 and it works fine.

    Only doesnt work fine if they're spawned before the client joined.

    1. one hosts(server+client)
    2. join with 2nd client alright
    3. spawn bunch of enemies (works)
    4. join with 3rd client (doesnt work he gets that warning again)
    the 2nd client and host can still play fine though..

    any idea how to solve this issue or bug? what is my mistake here?
     
    Last edited: May 19, 2023
  3. mrstruijk

    mrstruijk

    Joined:
    Jan 24, 2018
    Posts:
    52
    Hey! I had the same thing happen to me just now. Never had it before, didn't change anything Netcode related in the last weeks.

    When I disabled my VPN (NordVPN) it worked again! Weird thing is that I've had the same VPN for ages, and never had issues.