Need Help structuring utility AI for agents that can change weapons/skillsets

  • January 9, 2018 at 22:29 #22620

    In my game, AI units have access to several different skills and weapons. Its obvious that each weapon/skill should have its own scorer/targeting function (e.g. dagger attacks nearest enemy, heal will heal nearest ally, etc.), but I am at a loss as to how exactly I should implement this using Utility AI, considering these weapon/skill combinations can change in real-time. This seems like it should be a trivial task, it is a common use-case, but nonetheless the solution eludes me.

    What seems easiest to do is to check the agent’s inventory for equipped weapons and skills, and then generate the AI tree in realtime from a library of weapon/skill AI scorers, however it is not very clear given the documentation available how I might accomplish this. Also, this solution might hinder performance, since (I assume) single instance AI’s would no longer shared amongst agents.

    Alternatively, I could have a giant tree which evaluates every single weapon and skill scorer in the game, but first checks each weapon/skill scorer to see if the agent is actually wielding it. This option carries a bit of ‘code smell’, and could potentially become very unwieldy even with the editor provided, especially if a single weapon is capable of performing multiple different actions depending on different circumstances (e.g. “Reload Gun” and “Fire Gun” in the SurvivalShooter example).

    I would probably be fine with the above solution if I could ‘wrap’ multiple qualifier/action pairs (i.e. a Selector) into a single qualifier. For example, wrap “Reload Gun” and “Fire Gun” into a single qualifier “Use Gun”. “Use Gun” would evaluate its child qualifiers, and return the score of the highest child qualifier. If that score is chosen by the parent selector, then the “UseGun” qualifier would execute the action of the proper child. It isn’t clear given the documentation provided how I might implement this. I see you can set the ‘action’ property of the QualifierBase class, but I am unsure how to use the editor to hook up this ‘SelectorQualifier’ class. All this being said, I can’t shake the feeling that I’m just trying to do things in the wrong manner.

    Any help would be appreciated. Thanks!

    January 10, 2018 at 10:41 #22622


    Thanks for your post.

    First, I need to state that there are usually numerous ways to solve such a situation. The exact right solution sometimes take experimentation and actual in-game tests.

    That being said, it sounds to me like you are overcomplicating the situation. As you start by stating, each weapon or skill should have its own scorer(s), leading to an action. Scorers can be reusable (e.g. HasHealth above or below X), and you can combine multiple scorers easily in the editor.

    You probably do not need to write your own qualifiers at all. Most likely, you will just need to write scorers (IContextualScorer and IOptionScorer). The provided qualifiers usually suffice, e.g. “Sum of Children” and “All or Nothing” are the ones that I most commonly use.

    If you find that certain weapons have more complex behaviours, e.g. Reload and Fire for a gun, you can – as you state – wrap this up in its own action. E.g. the “Use Gun” action checks for ammo, if none, then reloads first, otherwise just fires. Alternatively, you can visualize this in the AI as well. I recommend using “Sub AIs” (with AI Links) to hide the complexity and to facilitate having small, easily maintainable AI assets that form a more sophisticated network together.

    Doing this would however require you to implement the needed scorers and set up AI nodes for each weapon/skill (or at least the ‘type’ of weapon/skill, if some can be treated equally). I do think this is preferable though, since everything is visual and easily tweakable through the editor. Breaking the AI up into smaller sub AIs will avoid having a huge, confusing AI tree.

    Actually doing dynamic instantiation of AI nodes within an AI asset is not recommend. Dynamically adding or removing AI assets to an AI agent is fine though, if that helps your use-case.

    March 19, 2018 at 13:18 #22916

    Ok, here’s the problem, but a bit more straightforward:

    Lets say you have a game that has 400 unique guns. Each gun requires a unique scorer based on things like how effective it is at a given range. You can equip each of your troops with up to three different guns.

    How do you design the AI to decide which of the three equipped guns to choose using the Apex Editor?

    It seems quite unwieldy to have the associated scorer for all 400 guns in a single AI object, especially considering the fact that on each iteration, all 400 scorers will be evaluated even though only 3 are equipped and usable.

    It would be much clearer, maintainable, and run-time efficient if one were able to build an AI selector out of equipped guns during run-time. I recognize that this would incur a memory cost (instead of having just one AI object for all actors, it would require a unique AI object instance for each actor), but for a closed source asset as expensive as this one, I would expect the tool to allow for that functionality if desired.

    Again, I’m at a loss at how to proceed with this tool, and it is frustrating as this feels like a trivial problem.

    • This reply was modified 4 days, 23 hours ago by mvcurtiss.
    • This reply was modified 4 days, 23 hours ago by mvcurtiss.
    March 19, 2018 at 14:03 #22920

    Hi Mvcurtiss,

    Thanks for posting again.

    I hope I understand your situation correctly.

    Your game has 400 guns in total. Each AI agent carries 3 guns. Each AI agent must at any time decide which of the 3 guns it wants to have equipped currently.

    Assuming I understood correctly, I can see several solutions to this situation using Apex Utility AI.

    The easiest and in my opinion most efficient solution would be to utilize the ActionWithOptions. This assumes that you can represent all guns using a common type (e.g. a common base class or interface). Then, you write an ActionWithOptions that takes the common gun type, along with a number of Option Scorers (IOptionScorer) that scores the common gun type based on what parameter is relevant, e.g. distance to target compared to range capability of the gun, etc.

    Then, your AI asset is very simple. You just have the ActionWithOptions, e.g. ‘ChooseGun’ on a node in the AI and then tweak the OptionScorer setup until you get the result you want.

    A simple but powerful solution for a trivial problem.

You must be logged in to reply to this topic.