Search Unity

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

Bug Can't despawn NetworkObject, CustomMessageManager throws error

Discussion in 'Netcode for GameObjects' started by Zaba_Dev, Nov 9, 2023.

  1. Zaba_Dev

    Zaba_Dev

    Joined:
    Feb 27, 2018
    Posts:
    16
    Hi, when I try to despawn the player's body object (it's not their player object) at the end of a round, I get this error:

    I'm pretty certain this used to work. Unsure if I updated or something. But I despawn objects with Netcode for Unity all the time, I don't understand why it wouldn't work.

    Code (CSharp):
    1.     public void DestroyPlayer()
    2.     {
    3.         myPlayer.GetComponent<NetworkObject>().Despawn();
    4.         hasPlayer = false;
    5.     }
    Within the Custom Message Manager, the first line of this method throws the error:

    Code (CSharp):
    1.         /// <summary>
    2.         /// Unregisters a named message handler.
    3.         /// </summary>
    4.         /// <param name="name">The name of the message.</param>
    5.         public void UnregisterNamedMessageHandler(string name)
    6.         {
    7.             var hash32 = XXHash.Hash32(name);
    8.             var hash64 = XXHash.Hash64(name);
    9.  
    10.             m_NamedMessageHandlers32.Remove(hash32);
    11.             m_NamedMessageHandlers64.Remove(hash64);
    12.  
    13.             m_MessageHandlerNameLookup32.Remove(hash32);
    14.             m_MessageHandlerNameLookup64.Remove(hash64);
    15.         }
     
  2. Zaba_Dev

    Zaba_Dev

    Joined:
    Feb 27, 2018
    Posts:
    16
    I can't even set destroyWithScene to true without the error being thrown. I can't see what makes this object different though
     
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    638
    Going by the error it looks like your NetworkTransform doesn't have a custom message handler assigned to it, which is a bit strange as that should happen on spawning. Was the NetworkTransform working up to the time of the Despawn call?
     
  4. Zaba_Dev

    Zaba_Dev

    Joined:
    Feb 27, 2018
    Posts:
    16
    Yes, works perfectly fine. Is there a way I can check to confirm there's no custom message handler? Because the error happens inside the Custom Message Manager, trying to call UnregisterNamedMessageHandler. Or does it? Looks to me like it does.
     
  5. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    638
    You can't access the name field but if you say it's working it sounds like it's set. The line numbers in your error don't match version 1.7 so you could always update NGO to see if that helps.

    If not can you explain how you're spawning it and if it's parented and I'll see if I can reproduce the error.