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

Seeking some tips when using the AI Planner

Discussion in 'AI & Navigation Previews' started by sordidlist, Jul 16, 2019.

  1. sordidlist

    sordidlist

    Joined:
    Sep 2, 2012
    Posts:
    86
    Hello,

    I've been trying to learn how the AI Planner works and I think I need some pointers regarding operational actions. I'm using 2019.1.10f1 with the preview ECS package removed as it seems like it isn't compatible yet.

    The manual says how to implement the operational actions, but I can't figure out when or in what context I need to write them. Are they one-to-one with actions in the AI planner UI? Do I need to write them from scratch, or do they get generated somewhere?

    Also, assuming I have a properly configured domain definition and plan definition, as well as some operational actions, and I have manually set up the interactable scene objects within the agent component, is that everything needed to make the AI Planner work? Is there anything special for having more than one agent?

    Somewhat related, I can't get the otto demo to load with a recent version of Unity so I haven't been able to use that as a reference just yet. I understand that it's a preview package so I'm not trying to urge anything unreasonable, I'm just excited to use this tool and wanted to ask.

    As a bonus question, the github repo is still the only way to install the ML agents code right? There isn't currently a preview package for that?

    Thanks!
     
    Last edited: Jul 17, 2019
  2. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    118
    Ah. I just responded to your post in the other thread. But I see you have additional questions, which I'll answer here.

    Operational actions are commonly one-to-one with actions in the planner. This is not a requirement, however. There are instances where to semantically different actions in the planner can share the same operational action. An example: for our Overcooked demo, picking up and dropping objects were handled by toggling a button press; on the planner side, we had separate actions for pickup and drop which shared the operational action of toggling that button.

    Once you've set up the domain definition, plan definition, operational actions, and the initial state (on the agent component, as you mentioned), you should be ready to go. One thing to keep in mind: if some external system in your project modifies the state of the world (as defined in the planning language), you'll need to update the state on the agent/controller. Such changes are not currently detected automatically (a feature coming soon!).

    For the Otto demo, did you open DemoScene?

    Lastly, there isn't currently a package for ML-Agents. That's in development by a separate team, so I can't say whether or not that's on the roadmap. You might try reaching out to them.
     
    eterlan likes this.
  3. sordidlist

    sordidlist

    Joined:
    Sep 2, 2012
    Posts:
    86
    Thanks so much for taking the time to clear that up for me! I think I'm on the right track now.

    Previously I had opened the DemoScene and Unity did this kind of half-loading thing, where the hierarchy listed the game objects but none of them appeared in the scene (I tried picking one and using F to find, I could see its transform but not the actual objects). Also the editor gave me an error about the scene being serialized by a different version of Unity. I haven't tried re-downloading it in a few days so I'll try it again this evening.

    Makes sense that ML Agents is a different team. Thanks again!
     
  4. winxalex

    winxalex

    Joined:
    Jun 29, 2014
    Posts:
    166
    In which namespace should need to be custom traits,rewards,effects,action...???
    Code (CSharp):
    1. Temp\PlannerAssembly\AI.Planner.Actions\TestPlan\InspectorGeneratedAction.cs(88,25): error CS0246: The type or namespace name 'CustomLocationActionEffect' could not be found (are you missing a using directive or an assembly reference?)
    2. UnityEditor.AI.Planner.CodeGen.PlannerAssemblyBuilder:Build() (at Library/PackageCache/com.unity.ai.planner@0.2.2-preview.1/Editor/CodeGen/PlannerAssemblyBuilder.cs:134)
    3.  
     
  5. mplantady_unity

    mplantady_unity

    Unity Technologies

    Joined:
    Jun 19, 2019
    Posts:
    49
    Your custom scripts need to be in their own assembly definition with dependencies to Unity.AI.Planner & Unity.AI.Planner.Custom.
     

    Attached Files:

    winxalex likes this.
  6. winxalex

    winxalex

    Joined:
    Jun 29, 2014
    Posts:
    166
    Let say you create ssembly definition, .asmdef, with name TestPlan, You need to have extension structs in following namespaces in order to be compiled correctly:
    Code (CSharp):
    1. namespace AI.Planner.Custom.TestPlan
    2. {
    3.     public struct CustomTraitReward : ICustomTraitReward<Agent>
    4.     {
    Code (CSharp):
    1. namespace AI.Planner.Actions.TestPlan
    2. {
    3.     public struct CustomLocationPreCondition : ICustomPrecondition<StateData>
    Code (CSharp):
    1. //namespace AI.Planner.Custom.TestPlan
    2. namespace AI.Planner.Actions.TestPlan
    3. {
    4.     /// <summary>
    5.     /// This will be shown in Action Inspector Object Modified
    6.     /// </summary>
    7.     public struct CustomLocationActionEffect : ICustomActionEffect<StateData>
    I couldn't find in the Trait List the custom Trait dough.
    Code (CSharp):
    1.  
    2. namespace AI.Planner.Custom.TestPlan
    3. {
    4.     [System.Serializable]
    5.     public struct CustomLocationTrait : ICustomTrait, IEquatable<CustomLocationTrait>
    Code (CSharp):
    1. namespace AI.Planner.Custom.TestPlan
    2. {
    3.  
    4.  
    5.     public struct CustomLocationHeuristicTest : ICustomHeuristic<StateData>
    Note which need to go into AI.Planner.Custom.NameOfYourASMDF and which AI.Planner.Actions.NameOfYourASMDF.
     
  7. mplantady_unity

    mplantady_unity

    Unity Technologies

    Joined:
    Jun 19, 2019
    Posts:
    49
    Notes, that we're working on a new solution for custom code that will be much simpler to setup.