Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Warning: Instance not found when handling Command message

Discussion in 'Multiplayer' started by asperatology, Oct 12, 2015.

  1. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    In a game, I have a non-player prefab, called List Manager, on the network game that has a list of game objects. This game object has been tagged as "List Manager". If a new game object is spawned in, this list will have the new game object added to it. If the new game object is destroyed, the new game object will be removed from the list. That's all the list is doing, just adding and removing new game objects to it.

    In this game, every player will have this non-player prefab list maintaining game object spawned. They are only to be controlled by the player as it is spawned in.

    I made it possible to update all of this non-player prefab's list through the use of GameObject.FindGameObjectsWithTag(). That means, if a player added a new game object to the list, I am able to make every single List Manager spawned in by other players to have this new game object be added to everyone's list.

    The problem of doing this, made the List Manager spat out this warning message when game objects are removed from the list:

    Warning: Instance not found when handling Command message

    This warning appears on the Server, and not on the remote Clients.

    What do I need to do about this warning?



    EDIT:

    Sometimes, I would get this UnityEngine error:

    HandleTransform no gameObject
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

    I cannot tell if it's because of my code, or it's an engine problem.
     
  2. _Adriaan

    _Adriaan

    Joined:
    Nov 12, 2009
    Posts:
    481
    How do you synchronise your list? It seems like you are trying to pass an object over network that doesn't have a networkidentity, am I correct?
     
  3. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    They all have Network Identities, and they are all registered on the Network Manager. I use the default network manager.

    I just grab all the game objects that matches a certain tag, and then have all of them be added into a list. If duplicate, ignore.
     
  4. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Bumping this thread. I am rephrasing the question to:

    How would I prevent the [Command] calls from being actually called on when a game object is destroyed? I found when a game object calls on a [Command], and during the [Command], the game object gets disabled/destroyed, the [Command] calls would not complete, signalling warning messages, like this:

    Is there a way to check to see if before [Command] calls, the game object is enabled/exists, and during [Command], the game object is still valid for [Command] calls?

    Thanks.
     
  5. Morgenstern_1

    Morgenstern_1

    Joined:
    Jul 1, 2013
    Posts:
    34
    Bumping this thread too, I am experiencing the same issue. Objects that have been destroyed mid-command are spewing these warnings into the console.
     
  6. Deleted User

    Deleted User

    Guest

  7. Deleted User

    Deleted User

    Guest

  8. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    277
    I could reproduce these messages by making an object destroy itself in a Command call, on the server as the message is processed (triggered from client). Everything works inside the message processing itself (so during the command everything is ok), but the warning appear afterwards. In my case they appear for the time it takes the server to tell the client to also destroy the object (destroyed on server via NetworkServer.Destroy so client eventually also does it). Essentially you just don't want the warning to appear for this scenario right? Where an object was just destroyed and you want silently discard any messages destined for it. The warning itself can't be removed since it could hide actual problems (maybe only for a limited time so you'll get them if the client never did delete his version of the object and keeps sending updates forever).

    There is no way to inject yourself into the place where a command is invoked, to do some custom checks like this. This could be added, but also these messages could just be circumvented by adding deleted objects to a list, temporarily, and when invoking commands (or any message) processing is stopped if the network ID is in that list. I don't think this can be hacked on top of the high level networking code, but it's pretty easy to do inside (see source), something like this:

    Code (CSharp):
    1. +++ b/Extensions/Networking/Runtime/NetworkServer.cs    Fri Mar 17 11:52:22 2017 +0000
    2. @@ -1243,6 +1243,13 @@
    3.              int cmdHash = (int)netMsg.reader.ReadPackedUInt32();
    4.              var netId = netMsg.reader.ReadNetworkId();
    5. +            // Object recently deleted, ignore this message
    6. +            if (instance.m_RemoveList.Contains(netId))
    7. +            {
    8. +                return;
    9. +            }
    10. +
    11.              var cmdObject = FindLocalObject(netId);
    12.              if (cmdObject == null)
    13.              {
    14. @@ -1485,6 +1492,8 @@
    15.                  uv.clientAuthorityOwner.RemoveOwnedObject(uv);
    16.              }
    17. +            instance.m_RemoveList.Add(uv.netId);
    18. +
    19. #if UNITY_EDITOR
    20.              UnityEditor.NetworkDetailStats.IncrementStat(
    21.                  UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
    22.  
    here I piggybacked on another list (which is regularly cleaned) but I could clean it up, cover other scenarios, add tests and commit it to the main source if it's useful.
     
    Deleted User likes this.
  9. Deleted User

    Deleted User

    Guest


    Yes, will be awesome. Because Log Filtering it's not that stuff that we want to use for ignoring warnings.
     
    Last edited by a moderator: Mar 19, 2017
  10. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Yes, that was my whole point for this thread. Because when the message is shown, that's after I've already made sure the client has disconnected from the server. I don't need to see that message anymore after the client has left the host.

    I see, I didn't ever think to use a temporary removed list this way. If this is the recommended way to go about, then I guess my issue is resolved, by redesigning how to go about from there, and modifying it so these checks will work to avoid seeing those warning messages.

    If possible, can this be included with the Unity docs? I hoped to see these snippets of info be added to the docs, because I'm pretty sure no one is going to know how to work on this problem unless one is persistent enough to find this thread detailing the solution.

    And that implies it's not possible to do when we're calling upon the default Network Manager? We would have to extend the Network Manager, and override its default functions?
     
    Last edited: Mar 25, 2017
    EPOHnomeL likes this.