Search Unity

Help with understanding Network ID's and lingering data.

Discussion in 'Multiplayer' started by sargasm_gaming, Oct 22, 2021.

  1. sargasm_gaming

    sargasm_gaming

    Joined:
    Aug 31, 2021
    Posts:
    1
    In the testing of my game I found a bug, which I can likely fix, but it made me find a potential future problem that I cant seam to figure out how to go about solving it (if it even would be an issue down the line). Hopefully someone can give me an answer or point me to a section of the documentation that I may have overlooked.

    Everything works cleanly from starting a host, to people connecting and playing to where I've created. The potential issue is after the host ends, and attempts to start a new hosted game. It would seam that the Network Id's from the previous game are still lingering somewhere.

    On the first time hosting a lobby, the hosted player is the first initial Network Object that is spawned, and receives a Network ID of 1. Then as other objects spawn in, they get subsequent IDs. However when stopping the host, and starting a new host, the Network ID's start at the next number of previous list of objects instead of what I thought would happen which would be that it reset and started back at 1.

    This may be by design, and/or not an issue. I created a test button to iterate through the list of network objects on the second host and it doesn't seam to point to any ghost objects or lingering data. What made me find this was I had an object with a Network Object script attached to it that was owned by the host and part of the scene (which I should probably just insatiate/spawn the object at the start of the host).

    The bug was that on the second time hosting, I would get an error message stating something along the lines of "looking for that object but it looks like it was destroyed" even though it was there, it was looking for the same object but with a different network ID. From my understanding of the documentations that I've read, is that Mlapi assigns the network id as soon as its created which would be why the second time loading the scene on the second host, it would attempt to point to the object that was "destroyed".

    Another concern is that after finding this, is that I'm not handling Mlapi starthost/stophost correctly, and previous data is still lingering. Also should I be destroying the Network Manager and any other Dont Destroy on Load objects and re-instantiating them when returning to the main menu or is that pointless and resource consuming.

    Thank you,
    Sarg