Apex Utility AI extensibility use cases

  • May 17, 2018 at 00:14 #23264
    predragradenkovic
    Participant

    Hello,

    My team is considering Apex Utility AI as a base framework around which we would like to build AI solution for our game.

    Before we make a final decision I would like to clarify some things that I couldn’t understand from your tutorials and demo projects.

    1) Is it possible to update specific AI in runtime? Let’s say that I have AI defined for my basic archetype, but on the spawning of the agent, I would like to add some specific behaviours that are not part of the basic archetype (for example in the root selector add one more qualifier with an action assigned to it). Can I do this in runtime and some documentation reference would be very beneficial?

    1.a) How about adding/removing whole AIs in runtime?

    2) Can I pause execution of specific AI in runtime?

    3) As far as I could understand, Apex Utility AI is always choosing one action (even if this action is the one that was previously chosen). This means that actions should be idempotent to avoid restarting of action. How I should handle actions that consist a couple of inner steps and should be executed over some period of time.

    Let’s take a simple example: Agent should execute the action of checking some position. This action consists of next steps:
    a. Go to position
    b. When arrive rotate to right for 60 degrees
    c. Then rotate to left for 120 degrees.

    How I managed to do this is by creating a MonoBehvaiour that implements this functionality and when AI triggers this action, I assign this component to the appropriate agent. On the next AI run, if AI again chooses the same action, I simply check if this component was already assigned [and if it is I skip the rest of the action and let the component do its job]. If AI chooses a different action, I remove this component from the agent. Is this the best approach how to handle such use cases using Apex Utility AI?

    4) Can I implement ActionWithOptions that combines the scores differently the just summing them? Let’s say that I want to calculate a weighted sum of scores assigned to one ActionWithOptions (or to simply multiply them instead of summing them). Can I implement my own ActionWithOptions or just extend the existing one?

    My apologies if any of those questions were already answered previously.

    Thanks in advance,
    Predrag

    May 18, 2018 at 14:32 #23269
    predragradenkovic
    Participant

    Hello,

    I managed to understand couple of details by going though available interfaces:

    1) Using LoadBalancedUtilityAIClient class I can access the IUtilityAI instance and access the selectors defined in it. The problem that I have at right now: there is no interface for removing or adding new qualifiers to the defined selector (I can only access them).

    Can someone explain if I can actually do this?

    1.b) I saw that AIs can be added in runtime easily using something like
    new LoadBalancedUtilityAIClient(AINameMap.PlayerBuildBots, player);

    2) It very simple. UtilityAIClient has interface for Pause/Resume/Stop execution of specific AI.

    4) I noticed ICompositScorer interface that I’ll try to use for this purpose.

    Regarding questions 3) it would be very beneficial to hear if the system was designed to work like this in the case of actions that are executed over longer period of time and require using of corutines. Is there any better/more efficient approach?

    Thanks,
    Predrag

    May 19, 2018 at 12:03 #23274
    Geminior
    Keymaster

    1) While you can add or edit Selectors, Qualifiers and Actions at runtime, it is important to understand that only one instance of any given AI exists.
    So if 10 agents use the same AI, that literally use the same AI instance. All state is held in the agent’s context which is passed to the AI when run for that agent.

    On the IUtilityAI interface you will find AddSelector and RemoveSelector. Selectors in turn have a list of Qualifiers you can add to or remove from and finally Qualifiers have an Action that can be set.
    However AI visualization wraps all of these, and attempting to add or remove anything while visualization is on, will fail as the visualizer don’t support that.

    So while it is possible to edit an AI at runtime, it means it will apply to all agents using that AI and you cannot use visualization at all.

    1.a) Depending on how you intend to associate AIs with agents, you can either enable/disable AI components on them, or you choose to manage AI assignements and ticking yourself you can add/remove as well.

    2) AI clients expose 4 methods to Start, Stop, Pause and Resume.

    3) Any and all state information is kept in the Context object (custom state for the AI).
    So in your example you could have a byte or enum variable to hold the step the action has reached.
    You could also include the progress of each step, e.g. how much has it turned and how much does ot need to turn, although I would recommend delegating such logic to Steering and simply have the AI query steering if it is done.

    Another thing to note about long running action is that some may need to be terminated if another action is chosen.
    For this actions can simply implement IRequireTermination which will allow the action to do whatever cleanup is necessary when it is terminated.

    4) You can implement your own version of the GetBest and GetAllScores methods.
    These methods are not virtual however so it will have to be new methods you create.
    This leads to the only caveat, namely that the visualizer for ActionWithOptions uses the GetAllScores method, so if you create your own visualization of scores for that action will not be correct.

    So why aren’t those two methods simply virtual then? No good reason I am afraid.

    You can also use a CompositeScorer as you suggest.

    May 19, 2018 at 19:28 #23276
    predragradenkovic
    Participant

    Thank you very much for the explanation.

You must be logged in to reply to this topic.