Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

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:
    18
    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:
    18
    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:
    700
    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:
    18
    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:
    700
    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.