Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Bug Possible bug: client cannot receive RPC from server in v1.2.0

Discussion in 'Netcode for GameObjects' started by Crazycarpet, Apr 1, 2023.

  1. Crazycarpet

    Crazycarpet

    Joined:
    Dec 5, 2015
    Posts:
    47
    Hey all, I recently updated an old project to Unity Netcode for GameObjects v1.2.0 from v1.1.0 and noticed that whenever the client connects to the server the clients console logs this error message: 'Trying to receive ClientRpcMessage from client 0 which is not in a connected state.'

    After some digging I have found that on all versions although NetworkManager.Singleton.IsApproved, NetworkManager.Singleton.IsServer, and NetworkManager.Singleton.IsClient are all true for the host after they start the server and are approved for connection the field NetworkManager.Singleton.IsConnectedClient is always false...

    In the version v1.2.0 this seems to be causing the 'Trying to receive ClientRpcMessage from client 0 which is not in a connected state.' error message when clients connect.Not only do I receive this error message the client does not receive RPC messages from the server (although the server receives them from the client).

    In v1.1.0 or older this seems to be no problem, even though 'isConnectedClient' is still false the client is able to reliably receive RPC messages from the server.

    Any insight into this would be appreciated. Does this sound like a bug I need to report or did something change in v1.2.0 that requires me to refactor my code? Thanks in advance for any ideas.

    EDIT: After viewing the source code I see the 'IsConnectedClient' field is set after scene synchronization or immediately after the approval callback if scene management is disabled. In my case I've disabled scene management but I've tested in both cases and neither work.
     
    Thasc likes this.
  2. Thasc

    Thasc

    Joined:
    Jul 24, 2013
    Posts:
    3
    I experienced this as well. In my case I was trying to call a ClientRpc method in a coroutine I had started in OnNetworkSpawn (and, while flailing for an answer, in an async void method I converted that coroutine into).

    I was using a coroutine because I wanted to re-check for the existence of an object, and only proceed with some logic if it was present, so I had a while loop containing the check, then a yield return new WaitForSeconds if it wasn't there yet.

    What fixed it for me was changing that whole OnNetworkSpawn->Coroutine faff to just using Update, and checking for the existence of the object in there. Basically replacing my while loop with the Update loop. Suddenly the mysterious warning went away and the client received the RPC I sent.

    So I'm not sure if there's some issue sending certain messages from coroutines, or from coroutines started in OnNetworkSpawn, but using Update was my fix.
     
    Last edited: Apr 10, 2023
    Crazycarpet likes this.
  3. Crazycarpet

    Crazycarpet

    Joined:
    Dec 5, 2015
    Posts:
    47
    It is definitely is a bug of some kind, I've solved this by downgrading to v1.1.0 for the short term. No time to file a bug report unfortunately.

    v1.1.0 works for my use cases so all is well. Hopefully someone with more time (or motivation) than me files a proper bug report so this can get solved sometimes in the next few years. :p

    Knowing Unity and the Unity forums however I'm sure a moderator will close this thread for some reason like 'not relevant', several people will report the bug, and then years will go by without a fix haha.

    It seems lots of Rpc related changes and improvements were made in v1.2.0 so I'm not surprised some bugs cropped up. It still could be that the use-case has changed completely and they just haven't properly documented the changes, who knows. Thankfully downgrading is a perfectly fine fix.

    Either way thank you for sharing your experience with this bug as well.
     
  4. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi @Crazycarpet , a few things:

    1. Did you try updating to 1.4.0?
    2. According to the doc, it could be that your OnNetworkSpawned is called too early (there are differences between in-scene objects and dynamic ones). What are you trying to do in that RPC?