Search Unity

Resolved Deferred messages were received for NetworkObject

Discussion in 'Netcode for GameObjects' started by ricoevilness, Jan 6, 2022.

  1. ricoevilness

    ricoevilness

    Joined:
    Dec 25, 2021
    Posts:
    2
    Hi there, I'm playing with Netcode in Unity for couple of days and today I got this warning message on server side only (not client side, neither host - which would mean both sides from what I understand so far).
    Here's a copied message.
    [Netcode] Deferred messages were received for NetworkObject #2, but it did not spawn within 1 second.
    NetworkObject number is regularly increasing.

    Now to explain what's going on. I'm basically spawning prefabs with script attached to it, which after 1.5s sends request to server to Despawn the object.
    It actually works alright, there's just this warning message showing up for each despawned prefab which I'm always concerned about :D Anyway, if I delete Despawn() instruction in ServerRpc request, messages won't show up but obviously prefab won't despawn.

    Of course, I have Network Object script attached to the prefab, and it's also set in Network Manager.

    Here's part of the code I'm using, thanks in advance for some explanation or correction :)

    Code (CSharp):
    1.  
    2. void Update()
    3.     {
    4.         transform.position += direction * speed * Time.deltaTime; //moving the prefab
    5.         float timeSinceSpawn = Time.timeSinceLevelLoad - spawnTime; //regular timer
    6.         if (timeSinceSpawn > 1.5f)
    7.         {
    8.             SumbitDestroyProjectileServerRpc(); //ServerRpc request
    9.         }
    10.     }
    11.     [ServerRpc]
    12.     void SumbitDestroyProjectileServerRpc()
    13.     {
    14.         GetComponent<NetworkObject>().Despawn(); //despawning object
    15.     }
    16.    
     
    Last edited: Jan 6, 2022
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    660
    I've seen this message but only on the client, where the server sends a message to a network object that hasn't yet spawned. I've also seen it with a clientrpc sending messages to the player object that didn't exist on the client, which I assume is a bug.

    In your case there could be pending messages that aren't reaching the network object before its despawned. You could try commenting out the change to the transform position just to see if it's the cause.
     
    Sacus likes this.
  3. ricoevilness

    ricoevilness

    Joined:
    Dec 25, 2021
    Posts:
    2
    Hey, thanks for quick reply :) I just realized what was the problem.
    It was actually caused by Update() function.
    Problem was if condition which is set to send request every time when timeSinceSpawn is higher than 1.5f. So Despawn() instructions were basically sent more than once and since the first instruction did its job, the rest was just excess and led to the warning message. I solved it with simple boolean check in the condition so my code now looks like this.
    Code (CSharp):
    1.  
    2. void Update()
    3.     {
    4.         transform.position += direction * speed * Time.deltaTime;
    5.         float timeSinceSpawn = Time.timeSinceLevelLoad - spawnTime;
    6.         if (timeSinceSpawn > 1.5f && despawnInstructionSent == false)
    7.         {
    8.             SumbitDestroyProjectileServerRpc();
    9.             despawnInstructionSent = true;
    10.         }
    11.     }
    12.     [ServerRpc]
    13.     void SumbitDestroyProjectileServerRpc()
    14.     {
    15.         GetComponent<NetworkObject>().Despawn();
    16.     }
    17.  
    Honestly, timeSinceSpawn = 1.5f might also do the job, but it feels way too precise to me (some anomalies might get around) and also another variable might be helpful later. :)

    Also, I hope this will help somebody later, since I couldn't google this message anywhere lol.
     
    Last edited: Jan 9, 2022
    Tyc1Up and cerestorm like this.
  4. Tyc1Up

    Tyc1Up

    Joined:
    Jan 27, 2021
    Posts:
    2
    Thanks for posting this! A simple bool check seems to have fixed my "Differed messages received OnSpawn" Warning. Very confusing though.... first of all, in my case, this was appearing when I was despawning , not spawning. Secondly, I have read that it is counter indicated to use FixedUpdate in NetCode so why would it try to call it multiple times in Update in the first place? Oh wel..... Works with the bool check.. Thanks!