Enable/Disable Individual AI at Runtime

  • July 17, 2017 at 14:38 #21415
    shawn.m.wignall
    Participant

    I have about 25 small AI for each unit. At the root of each one I have a quick “bail-out” check to see if the rest of that AI needs to be executed, to try and avoid wasted processing. What I’ve found is that I still have a lot of issues. When I actually disable the unneeded AI in the inspector and run I have significantly better performance, even though there is very little in those AI that happens.

    Question: Can I enable/disable the individual AIs at runtime? I’d like to turn off most of them when they aren’t needed, and then turn them back on when they are.

    July 18, 2017 at 17:03 #21429
    creo
    Participant

    It’s possible to access the individual AIs. For example, if you wanted to pause all of them, you could add a using directive for Apex.AI.Components, then do something like this:

    August 1, 2017 at 11:20 #21580
    Rami
    Keymaster

    Hi Shawn,

    Thanks for posting, I apologize for the late response. Also thank you Creo for chiming in. You are very correct in your example.

    I just wanted to add that there are more ways to enable and disable AIs: Toggle the component state (Component.enabled), Toggle the GameObject state (GameObject.SetActive), call Stop() or Pause() on the UtilityAIComponent or on the individual clients. The first two are standard Unity ways of enabling/disabling objects, and Apex Utility AI will respect these.

You must be logged in to reply to this topic.