LoadBalancer and SceneManager.LoadSceneAsync

  • May 20, 2017 at 12:52 #20775
    CrytivoGames
    Participant

    Hello.

    I’m using LoadBalancerComponent in my scene. At runtime I’m starting AIs and they work perfectly. LoadBalancerComponent shows exact number of running AIs.

    Now, if I run/stop the scene then everything is smooth and LoadBalancerComponent shows 0 AIs at start. But, if I do following steps (see a bit below), then LoadBalancerComponent will show that it has some AIs running already, although I have not started any yet.

    Steps:
    1 – Start scene.
    2 – At runtime start few AIs
    3 – reload same scene using SceneManager.LoadSceneAsync

    Apparently there are some persistent data that is not cleared on scene load. Am I doing something wrong? What should I do to stop all AIs at once?

    Thanks.

    May 22, 2017 at 10:26 #20791
    Rami
    Keymaster

    Hi CrytivoGames,

    Thanks for your post.

    The load balancers are not automatically cleared on scene loads. Assuming that you are using the default LoadBalancedUtilityAIClient through the default UtilityAIComponent, they should unregister themselves OnDisable.

    However, I’m not entirely sure how Unity manages the life cycle of game objects in a scene that is asynchronously reloaded, i.e. whether OnDisable is called on all game objects in that scene.

    You could try simply iterating through all UtilityAIComponents and call Stop() on them, or disable them as that calls Stop() too.

    May 22, 2017 at 10:57 #20794
    CrytivoGames
    Participant

    Hi,

    We don’t use UtilityAIComponent. We start our AIs via LoadBalancedUtilityAIClient. We do something like:

    A method like “AIManager.StopAllAIs” (or similar) would be handy. Of course I could try and register a list of all current AIs and then iterate it, but it seems like a hack to me. :)

    Regards.

    May 22, 2017 at 14:41 #20796
    Rami
    Keymaster

    I can see how such a start/stop all AIs method would be beneficial, unfortunately there is no such method currently provided.

    Thus, you will need to keep a list or other type of collection with all your clients, so that you can call Stop() on each of them.

You must be logged in to reply to this topic.