Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Deferred messages warning upon client-authoritative Despawn()

Discussion in 'Netcode for GameObjects' started by Kwipse2, Sep 16, 2023.

  1. Kwipse2

    Kwipse2

    Joined:
    Jul 26, 2023
    Posts:
    1
    Hello !

    I'm trying to make a basic client-authoritative projectile, with a ClientNetworkTransform and a NetworkRigidbody, that will send an RPC to despawn itself when it collide with anything.

    Everything works as intended, except my server is spitting the following warning, 1 second after any client(host is working fine) projectile is despawn :

    [Netcode] Deferred messages were received for a trigger of type OnSpawn with key XX, but that trigger was not received within within 1 second(s).

    Here is the script for the projectile :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.Netcode;
    5.  
    6. public class Saucisse : NetworkBehaviour
    7. {
    8.     public int Speed = 1000;
    9.     Rigidbody rb;
    10.  
    11.     public override void OnNetworkSpawn()
    12.     {
    13.        if (IsOwner)
    14.        {
    15.            rb= GetComponent<Rigidbody>();
    16.            rb.AddForce(transform.forward * Speed);
    17.        }
    18.     }
    19.  
    20.     void OnCollisionEnter(Collision collision)
    21.     {
    22.         if (IsOwner)
    23.         {
    24.             PingServerRPC();
    25.             DespawnServerRPC();
    26.         }
    27.     }
    28.  
    29.  
    30.     [ServerRpc]
    31.     void PingServerRPC(ServerRpcParams serverRpcParams = default)  
    32.     {
    33.         var clientId = serverRpcParams.Receive.SenderClientId;
    34.  
    35.         Debug.Log($"Server PING from client {clientId}");
    36.     }
    37.  
    38.  
    39.     [ServerRpc]
    40.     void DespawnServerRPC(ServerRpcParams serverRpcParams = default)  
    41.     {
    42.         var clientId = serverRpcParams.Receive.SenderClientId;
    43.  
    44.         GetComponent<NetworkObject>().Despawn();
    45.     }
    46.  
    47. }
    48.  
    When there is a collision on the client :
    - If I only call PingServerRPC() : Server gives the ping
    - If I only call DespawnServerRPC() : Server gives the warning
    - If i call PingServerRPC then DespawnServerRPC() : Server gives the ping then the warning

    Other thoughts :
    - When I call DespawnServerRPC() from somewhere else than OnCollisionEnter(), I get no warning