Search Unity

Reset network manager

Discussion in 'Multiplayer' started by marcV2g, Jul 25, 2017.

  1. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    So if If I leave a scene with a network manager and it gets destroyed the next time I try to start one up I get:

    NullReferenceException: Before using the library you should call Init() and do not forget to call Shutdown() afterwards
    UnityEditor.NetworkDetailStats+NetworkOperationDetails.NewProfilerTick (Int32 tickId) (at C:/buildslave/unity/build/Editor/Mono/Profiler/NetworkDetailStats.cs:118)
    UnityEditor.NetworkDetailStats.NewProfilerTick (Single newTime) (at C:/buildslave/unity/build/Editor/Mono/Profiler/NetworkDetailStats.cs:209)
    UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:1095)

    How can I reset the network system?
     
  2. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    Does anyone know, I really need a way top force the network system back to its default starting state.
     
  3. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Have you tried what the message tells you?
     
  4. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    do I call init on the low level api or the network manager?
     
  5. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Are you using LLAPI or HLAPI?
    Seems by the messages like you are using HLAPI.
    I guess just before you destroy the NetworkManager. Do NetworkManager.Shutdown();
     
  6. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    I am using HLAPI but I do still get a lot of LLAPI errors. I am trying to make it shut down properly but would still like a way to prevent the app from being permanently broken if a scene is exited incorrectly.
     
  7. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    If a scene is exited incorrectly? Just make sure to shut it down before exiting the scene? Or even simpler. Never destroy the NetworkManager.
     
  8. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    After looking at the HLAPI code StartClient calls NetworkTransport.Init. Does the LLAPI have a get state method so I can see if it needs to be shutdown before it starts?
     
  9. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Not that I know of. But why don't you just Shut it down before the scene is changed? Or never destroy it at all
     
  10. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    I will see if calling it in OnDestroy works but for not destroying it on my current project it is in a stage where its a bit late to totally change how scene transitions work.
     
  11. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    You don't have to change how transitions work. There is a option on the networkmanager called "DontDestroyOnLoad". Tick it and the NM will remain across scenes.
     
    xVergilx likes this.
  12. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    Will it prevent multiple instances being created if I go to the same scene again?
     
  13. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
  14. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    I currently have two network managers because Unity has a odd idea of what a singleton is.
     
  15. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
  16. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    Is there any to to suggest to Unity

    void Awake()
    {
    InitializeSingleton();
    }

    Be changed to:

    protected virtual void Awake()
    {
    InitializeSingleton();
    }
     
  17. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    You can download the Bitbucket project. Change the sourcecode. Compile it to a DLL. And replace your current one with that one.
    Further instructions:
    https://bitbucket.org/Unity-Technologies/networking/overview