Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

AI planner seemed promissing but feels too rigid

Discussion in 'AI & Navigation Previews' started by Ashkan_gc, Jul 4, 2019.

  1. Ashkan_gc


    Aug 12, 2009
    I was looking for an AI solution which allows me to make my agents in the game in a way that they have a complex set of behaviors and have emotions. Imagine sims AI 2.0.
    I came across utility theory and your planner and planners in general.

    While utility theory allows me to really define what will happen, although i'll not explicitly define each state/transition. The planner in general feels very black boxy and hard to work with. It feels good for finding high level strategies and things which you want to find near optimal solutions for but, modelling uncertainty, mistakes and … inside the domain language to make it create incorrect plans is hard and also the implementation is very limiting since the cost and reward of an action cannot be defined in code or if it can , I missed it.

    It would be good if you shed some light on this.
  2. TrevorUnity


    Unity Technologies

    Jun 28, 2017
    You are correct in that our tooling/UI does not support uncertainty or complex cost/reward calculations. In code, however, we've exposed methods you can implement for these use cases. I'll point you to a couple of examples.

    For custom rewards, you'll need to implement SetCustomReward on each action that you want custom rewards for. We did this in the Otto project for navigation, as we wanted the cost to be proportional to the distance traveled. (See: Navigate.Extra.cs )

    For non-determinism, you'll want to modify the action effects. We have an example of this in the package tests, which you can reference (Packages -> AI Planner -> Tests -> Runtime -> KeyDomain -> UnlockRoomAction.cs). I'll paste the code here:

    Code (CSharp):
    1. protected override void ApplyEffects(Permutation permutation, Entity parentPolicyGraphNodeEntity, Entity originalStateEntity, int horizon)
    2. {
    3.             var actionNodeEntity = CreateActionNode(parentPolicyGraphNodeEntity);
    5.             horizon++;
    6.             var stateA = TraitBasedDomain.CopyState(EntityManager, originalStateEntity);
    7.             UpdateState(stateA, permutation, Color.Black);
    8.             SetActionData(stateA, originalStateEntity, parentPolicyGraphNodeEntity, horizon, actionNodeEntity, value: 1f, probability: 0.4f);
    10.             var stateB = TraitBasedDomain.CopyState(EntityManager, originalStateEntity);
    11.             UpdateState(stateB, permutation, Color.White);
    12.             SetActionData(stateB, originalStateEntity, parentPolicyGraphNodeEntity, horizon, actionNodeEntity, value: 1f, probability: 0.4f);
    14.             var stateC = TraitBasedDomain.CopyState(EntityManager, originalStateEntity);
    15.             UpdateState(stateC, permutation, Color.Black, true);
    16.             SetActionData(stateC, originalStateEntity, parentPolicyGraphNodeEntity, horizon, actionNodeEntity, value: 10f, probability: 0.2f);
    17. }
    I hope that clears up the issue for you! Let us know if you have more questions.
    zephyr831125 likes this.