Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

AI Planner - v0.2-preview released

Discussion in 'AI & Navigation Previews' started by amirebrahimi_unity, Dec 7, 2019.

  1. mplantady_unity

    mplantady_unity

    Unity Technologies

    Joined:
    Jun 19, 2019
    Posts:
    32
    Yes the Planner is using Jobs internally (and burst) and can run on multiple frames, you can give a budget for the search with different settings (time, max plan size...)
     
  2. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    3,603
    in the first page of the documentation please add minimum unity version required
     
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    3,603
    just ran a quick bench on the vacuum robot sample to see if it could be used in an open world
    it can't
    with leaks off and all debugs off I'm getting these:
    upload_2020-6-13_23-57-41.png
    it's slower than non bursted non jobified equivalent BT like PandaBT when using physic's overlapsphere
    with jobs and burst I'd expect crazy performances on a 6 core 8400 so I'd like to see something that showcases it, unless massive optim are in the work.
     
  4. Djayp

    Djayp

    Joined:
    Feb 16, 2015
    Posts:
    92
    Hello @laurentlavigne ! I'd be interested in the profile at runtime if you could ?
     
  5. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    3,603
    upload_2020-6-14_19-30-12.png
    spikey
     
    Djayp likes this.
  6. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    Yes, all of the planning occurs within jobs. The package exposes parameters for adjusting how much search is scheduled at each frame, however the package does not provide an "automatic" load balancer.
     
    Roycon likes this.
  7. Djayp

    Djayp

    Joined:
    Feb 16, 2015
    Posts:
    92
    Will it be using entities 0.11 or 0.12 ? 0.12 won't support 2019.x
     
  8. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    720
    Quick question. Are there any plans to make the AI Planner use nodes/GraphView framework?
     
    vx4 likes this.
  9. cdm456852

    cdm456852

    Joined:
    Nov 21, 2017
    Posts:
    32
    Does this AI Planner package compatible with the ECS way of writing code? Like I have an entity, And I want to let this entity to complete some goals with some incentive, How can I do that?
     
  10. mplantady_unity

    mplantady_unity

    Unity Technologies

    Joined:
    Jun 19, 2019
    Posts:
    32
    We're still evaluating if we move the min requirement to 2020.1. Our goal would be to follow as much as possible latest DOTS releases in this case
     
    Djayp likes this.
  11. mplantady_unity

    mplantady_unity

    Unity Technologies

    Joined:
    Jun 19, 2019
    Posts:
    32
    It is in our long term plan to have an AI framework that uses node-based graph tools and having the Planner compatible with that.
     
    Grimreaper358 likes this.
  12. mplantady_unity

    mplantady_unity

    Unity Technologies

    Joined:
    Jun 19, 2019
    Posts:
    32
    We moved Traits to ECS ComponentData in our latest version to have an easiest bridge with entity/system.
    With the modification to the package release cycle, we're still evaluating when and how we will share the next public version.
     
  13. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    598
    Can u share more about AI framework that uses node-based graph tools? Long time ago I ask about the development of DOTS behavior tree. Will DOTS behavior tree preview package be available anytime soon?
     
    vx4 likes this.
  14. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    127
    will you support `async/await` in action callbacks?
     
  15. cbevelle20

    cbevelle20

    Joined:
    Apr 5, 2020
    Posts:
    6
    Hi, how do you recommend making a plan within a plan like a macro plan?Is there a certain process needed to make one plan recognise another? Or is the concept of macro plans implied by another plan changing the states that relate to the second plan?
     
  16. mplantady_unity

    mplantady_unity

    Unity Technologies

    Joined:
    Jun 19, 2019
    Posts:
    32
    It is still in our plan but don't expect anything soon. You can also take a look to DOTS Visual Scripting tool that is evolving a lot and could fit with some of your needs.
     
    optimise likes this.
  17. mplantady_unity

    mplantady_unity

    Unity Technologies

    Joined:
    Jun 19, 2019
    Posts:
    32
    We plan to make operational actions more flexible to allow developers to create their own control flow, so it may not be a built-in option, but it should be possible to do it.
     
  18. mplantady_unity

    mplantady_unity

    Unity Technologies

    Joined:
    Jun 19, 2019
    Posts:
    32
    Currently the way to do hierarchical planning, is to have multiple plans operating at different timescale, and like you said changing the state of the other plan by modifying the world state (object/traits)
     
  19. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    127
    hi, folks, i have a question that is why we have domain language in the first place? it cause codegen time and recompile time, and sometimes crush my UnityEditor, maybe you have already answered somewhere else, can anyone show some refs?
     
  20. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    18
    I have been experimenting with the AI Planner, and my current issue is that, even if the actions are executed in the planner, the Methods on my script are never called.

    I also created modifiers that should alter the trait state, but those modifications never actually get applied.

    The strange part for me is if I switch to `Use Next Plan State` instead of worldstate the functions get called on my script.

    I might have miss understood the difference between the `Next State Update` functionality, but shouldn't the methods be executed in both cases?
     
  21. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    I'm going to answer based on my interpretation of your question, but if it is incorrect, please let me know!

    My interpretation: "Why do we have a domain language... {as opposed to using data types from game code directly}?"

    There are many constraints that would make arbitrary data support difficult to support. For instance, the planning jobs run in the Unity Job System, which only accepts blittable data types, meaning we can't support class types for state data.

    Secondly, what is not apparent from the package but is a factor in this decision: the data used to describe the state of the world takes different forms in different contexts. On game objects, it's monobehaviour components On entities in the game scene, it's component data. In the planning simulations, it's packed into buffers in ECS. Each context has a different data access need in order to be correct as well as performant. I feel your pain when it comes to code generation problems (you could argue no one runs into this more than we do), but code generation is actually a very useful solution to this context problem. You author your data/traits once, and we generate the appropriate code for each different context where it might be used.

    I'd like to assure you that the pains of the code generation process will be eased as we move forward. Many teams at Unity are increasingly adopting code generation for various purposes, and there are many active discussions about how to make the process both correct and (hopefully) painless for our users. At the moment, I don't have any details on how or when it will improve, but it certainly among our top priorities.
     
    filod likes this.
  22. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    I'm going to address some of your points out of order. I hope that's not too confusing!

    I suspect this is the core issue. When you alter the traits in your methods, do you set the trait data back on the object? When you pull trait data from an object, you're working with a local copy, as it's a struct/value type. In order for the data to change, you have to reassign it back on the object.

    To track the execution of the plan, the controller updates its current state using either the world state (pulls in current data from the objects in the scene) or from the `Next Plan State` (i.e. the predicted state from the last action performed). If your changes to trait data aren't applied, querying the world won't pick up any changes, so it will think it's still at the same state. Using the next plan state "works" because it's pulling the state from the simulated changes, in which the effects are applied. If my suspicions about changing the trait data are correct, this should fix the world state option.

    At the very least, the method for the *first* action of the plan should be called. Look into trait assignment first, and hopefully this will be resolved as well. Let us know!
     
  23. cbevelle20

    cbevelle20

    Joined:
    Apr 5, 2020
    Posts:
    6
    Hi, is there a way to make 1 decision controller perform multiple coroutines at the same time without having to script this manually?
     
  24. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    There's no method of doing this in the inspector or settings, no. However, this shouldn't require much code to manage multiple coroutines, no? I've not tried it, so maybe I'm underestimating the required work.
     
  25. cdm456852

    cdm456852

    Joined:
    Nov 21, 2017
    Posts:
    32
    When dosing your next version released? Is that version that will support ECS Way of writing code?
     
  26. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    18
    Hey @TrevorUnity, thank you for the quick answer.

    Indeed that was the issue, I hadn't grasped that there is a clear abstraction layer between the planner and the actual execution.

    After modifying my implementation to actually modify the traits properly all seems to be working.

    Framerate appears to not ideal yet even with only a few options available to the planner, but I assume that has partially to do on how I have set up my example scenario.


    The world has Plantation Fields, Seeds, and a Farmer.

    The Planner Has 5 Actions: Idle (do nothing), Pickup Seed, Plant Seed, EatFood and Navigate.

    The idea is that the planner should figure out that the farmer can plant a seed into a field to obtain a fruit which he then can eat to get the highest rewards.

    It is working but if I don't give a clear termination condition (hasEaten) the planner continuously replans if there are no more seeds available, which puts a lot of strain on the CPU.

    I can of course share the sample project, but I'm just wondering what I might be doing wrong that even in this rather simple scenario (with only 2 seeds and 2 fields) it seems to not be able to solve it in an efficient way to be useable.
     
  27. cbevelle20

    cbevelle20

    Joined:
    Apr 5, 2020
    Posts:
    6
    Thanks for the reply @TrevorUnity. I am working on doing this, but looking at the online forums a lot of people struggle with it. Like in my case after my first actions finish, the plan starts glitching when trying to find the next step and it seems to be stuck in a loop trying to figure out the next method to perform. I checked the parameters and it should be able to continue planning.

    Something I really like about the AI planner is the ability to see each action occurring which helps with multiagent cooperation and makes the complicated parts very explainable. But if I am hard coding the management of multiple coroutines then I lose some of the benefits of the plan visualizer used in the AI planner which is very nice to track what is happening and why. When I gave each agent their own decision controller it worked at times, but eventually ran into errors or conflicts when multiple agents needed to work together. I am making progress though.

    Question1: When there are more than one decision controllers within the same plan, but one controller has no involvement in one or more actions of the plan, should we leave the method blank and use that object as the callback? Or should we leave the object empty or just use something like UpdateStatefromWorldQuery as the method?

    Question2: For an action should we list all possible states from that action as the items to modify? I ask because I read in the forums that we put in what is expected to occur, but what if there are multiple outcomes for example by performing this action you could have a vehicle breakdown or successful task or be destroyed. Should we make 3 actions or 1 action with each case as a parameter to modify?
     
  28. Noxalus

    Noxalus

    Joined:
    Jan 9, 2018
    Posts:
    61
    Hi @HolonauticMaster, I have the same issue relative to the trait state that I change through "Modify", but the state is never updated :/

    upload_2020-7-16_15-20-23.png

    Here is my action: there is a spot where I want to send my agent, and when he reaches the spot, the IsAvailable property must be set to false.

    But every time I spawn a new agent, he goes to the spot already occupied...

    I don't know if it supposed to be updated in the TraitComponent, but the value is still the default one:

    upload_2020-7-16_15-24-6.png

    What do you mean by:

    You updated the coroutine called as your action's callback to update the corresponding trait data?
     
    Last edited: Jul 27, 2020
  29. cbevelle20

    cbevelle20

    Joined:
    Apr 5, 2020
    Posts:
    6
    Hey @HolonauticMaster, I just had a similar issue. I got mine working by passing that parameter for the objects to be modified into the method at the decision controller. Then in that method at the end of the routine, I do something like agent.GetComponent<TraitComponent>().GetTraitData<InsertNameofTrait>().SetValue("NameofField", value). This is done for each modification from what I gather.

    For the relevant script with the method, this will be attached to the object containing the decision controller. Then it will also need the namespaces:

    using UnityEngine.AI.Planner.DomainLanguage.TraitBased;
    using Generated.AI.Planner.StateRepresentation;

    Also. I used the World State for the methods to Update.

    Anyone correct me if I am wrong.
     
    Noxalus likes this.
  30. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    We are changing our release cycle to line up with other R&D teams to ensure compatibility between packages/dependencies. I don't have a firm date for our next release yet, but it will likely come in August. Pure DOTS support has been deprioritized in favor of hybrid workflows for the time being.
     
    quabug and laurentlavigne like this.
  31. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    Do you have Burst enabled?

    Have you considered adding a termination condition for when there are no more seeds available?
     
  32. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    Ah. Yes, the visualizer is handy for tracking the process of planning, but we have no tooling to track the status of acting. In an older version of the package, actions were effectively coroutines that returned information regarding its status (running, complete, invalid/interrupt). However, the form of such actions was a bit constrained for the wide variety of action implementations people wanted. Shifting to performing actions by invoking user method callbacks unfortunately meant the burden of tracking such execution is now on the users.

    Let me see if I understand your question correctly. Are you sharing a plan between multiple agents executing the joint plan? How synchronized should the actions of the various controllers be? I'd imagine if each performed a part of some joint/group action, you'd want each to query for a new world state only after each controller's action has completed (so as to not miss any changes that are still ongoing).

    At the moment, our editor tools don't allow you to specify multiple results. That said, the planning process itself does support non-deterministic action outcomes, but if you want to take advantage of that, you'll need to modify code. If you look in the generated action code (same name as your actions asset), the key part you'll want is to add additional StateTransitionInfoPairs<...>, which hold information about which states/actions are connected and by what probabilities (ensure they sum to 1!).
     
  33. cbevelle20

    cbevelle20

    Joined:
    Apr 5, 2020
    Posts:
    6
    Thanks, I got my issues all working now. I figured out how to handle the coroutines now. I am new to Unity and C#, but I'm getting there slowly.

    Also, I was able to make the multiple agents work properly under the same (joint) plan by doing like you said to query the world state. I left the cooperative task to a separate decision controller for the system but this time using logic for an exit the routine sent to the individual agents when called by a more important routine from the system decision controller. Then I give independent agent tasks to the agent's own decision controller like it was done in the vacuum game limiting what else that agent can see. Thus giving the multiple coroutines in parallel. This system is amazing for explainable AI! I'm including scenarios with this tool in my dissertation project.

    Thanks for responses.
     
    amirebrahimi_unity likes this.
  34. cbevelle20

    cbevelle20

    Joined:
    Apr 5, 2020
    Posts:
    6
    Hi, is there a way to make the plan visualizer show previously performed actions. It appears that after an action is taken, the past information is lost.
     
  35. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    Glad to hear it! If you want to discuss your dissertation project sometime, I'd be happy chat!

    As for showing previously performed actions, there is not currently a way to do it. The data for prior actions is disposed of once the graph is updated to a new root, pruning out unreachable states. Until we change that logic, I'd recommend logging the actions in your callbacks as they are executed.
     
  36. unikum

    unikum

    Joined:
    Oct 14, 2009
    Posts:
    55
    Would love to start implementing this in my game, but I rely on later entities version. Any rough estimate when you will be able to update dependency to later version of entities?
     
  37. Djayp

    Djayp

    Joined:
    Feb 16, 2015
    Posts:
    92
    I wonder if you considered making the trait based language a separate package ? Serialized operations, traits and action definitions are pretty nice concepts.

    Just a bet, but since they said they're moving toward 2020.1 mid-august, and they want to match with the latest Entities package, I'd say we should wait for Entities 0.12.
     
  38. Noxalus

    Noxalus

    Joined:
    Jan 9, 2018
    Posts:
    61
    Thank you for the answer, I will try that, but what is the purpose of specifying changes in the "Objects Modified" fields if it actually does nothing?

    Is that really the proper way to do that? @TrevorUnity
     
  39. mplantady_unity

    mplantady_unity

    Unity Technologies

    Joined:
    Jun 19, 2019
    Posts:
    32
    Exactly, we moved traits in its own package, with a more complex query system (based on ECS) and new authoring tools. It should be available as a standalone package in the future.
     
    banan1234, Djayp and laurentlavigne like this.
  40. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    While updating our package to the latest entities version, we discovered a bug which has required a fix in Unity itself. The issue has since been resolved, however the bugfix is not yet in a publicly released version of Unity (coming in a near-term 2020.2 release; will be backported to 2020.1). Unfortunately, this means it might be several weeks before we can publish a new version of the AI Planner.
     
  41. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    What you're authoring in the action definitions are the predicted effects, as used by the planning algorithm. It's a model used by the agent to reason about the future. It's not meant to define gameplay directly, as it represents a more condensed version of what actually happens. For example, a simple "Eat" action may involve playing an animation, only resetting hunger at the appropriate frame. It is also common for the predicted effects to not line up with what happens in the game. If an agent decides to go pick up an object but the player steals it first, then it is not appropriate to apply the predicted effects to the game state, as the agent cannot pickup the object. These are two of the primary reasons there is a distinction between the model of the action---which you author as an Action Definition---and the actual execution of the action, which is left to whichever user-provided callback you specify on the DecisionController.

    Now, is the distinction made clearly enough in our package/tool? No, I believe we can do a better job here. You are not the first to be tripped up on this point. We're open to suggestions!
     
    Noxalus likes this.
  42. Du-z

    Du-z

    Joined:
    May 10, 2013
    Posts:
    4
    Hey guys, I have been having a go at implementing a needs system that is similar to what has been implemented in Prison Architect.

    At first I tried to make a generic need and needFulfiller trait that uses an enum to designate the need type. The idea being I can do an equality comparison for need.needType and needFulfiller.needType.

    However I hit a roadblock when trying to assign many generic needs to a single agent as it only allows a single need trait to be assigned to a single Trait Component.

    At the moment I have split my 9 traits into their own need, needFullfiller and needAction which works fine but seems a bit clunky having 9 traits all with identical actions.


    Some thought on how it could be made to work:

    1. Multiple Trait Components on a single agent, not sure how that would interact with the Plan Definition and
    Decision Controller though.

    2. Adding a 'Genericized' enum property to a Trait so when the code generation is run it make classes along the lines of:-

    Code (CSharp):
    1.  
    2. public struct NeedTrait<T> : ITrait, IEquatable<NeedTrait<T>>
    3. {
    4.     // All the normal Trait 'stuff' goes here
    5. }
    6.  
    7. public struct FoodNeedTrait : NeedTrait<NeedType.Food>
    8. {
    9.     // A empty wrapper around NeedTrait<T>
    10. }
    11.  
    12. public struct SleepNeedTrait : NeedTrait<NeedType.Sleep>
    13. {
    14.     // A empty wrapper around NeedTrait<T>
    15. }
    16.  
    Something similar would probably need to be done for the satisfyNeedAction too.


    3. Maybe I could use Custom Traits to get the same affect as idea 2?

    Even with needing to create individual tasks, I am rather impressed by how little effort is required to get decisions being made, thanks for the hard work.
     
    Last edited: Jul 28, 2020
  43. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    Hi, @Du-z! I believe I have a pattern that should work for you. First, let me explain why we haven't supported some of the solutions you suggested (just for clarity).

    In practice, this can be confusing or error-prone, as we tend to operate on game objects as a whole rather than individual trait components, meaning there's likely a chance of reading/writing to/from the wrong component. We have seen some of our users spawn child objects to hold trait components, though I haven't personally worked with such a structure.

    So it seems possible that we could support generic/templated trait types, given that entities supports generic component data with known/registered instances (e.g. MyTrait<int>). However, I don't believe we can operate on entity data without knowing the full type (we can't use MyTrait<>), so I'm not sure where it would be advantageous to support those traits. It might make authoring easier, but we'll have to think a bit further about how that would look.

    Alright, here is a pattern you can use for having various needs. I'm trying to stick closely to what you've described. The key, as you identified in your suggestion #2 is to use an enum to define the need type.

    upload_2020-7-28_13-48-14.png

    From this, you can define a "generic" Need trait, the type of which depends on its NeedType (a property of the trait).

    upload_2020-7-28_13-49-12.png

    I've also added a value field (NeedValue) and an object reference to define the object that has the need (NeedOwner). To fulfill a need, you mentioned a "needFulfiller", for which I've also created a trait:

    upload_2020-7-28_13-50-44.png

    You could optionally add a value for how much of the need is satisfied by interacting with the object.

    Finally, let's look at an action to handle this interaction, which I've called SatisfyNeed:

    upload_2020-7-28_13-51-54.png

    This is really just the skeleton for such an action. You don't actually need the first parameter, NeedOwner, but I've included it as an example of how to specify the object possessing the need. What's key is the precondition matching the need with the object that can fulfill that need. That will ensure the plan reasons about the correct interactions between objects fulfilling needs and the needs they fulfill. Hopefully this type of pattern will unblock you! Keep us posted.
     
    eugolana likes this.
  44. eugolana

    eugolana

    Joined:
    Mar 27, 2019
    Posts:
    6
    Could anybody explain how to get hold of a 'TraitDefinition' for 'AddDefaultTrait'?
    I want to be able to add a 'globallyvisible' trait to objects in certain circumstances.

    I can't find an example of either 'TraitDefinition' or 'AddDefaultTrait' in the samples.

    Thanks for all the gret work on this. I'm really looking forward to the next release!
     
  45. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    I'm not sure I understand what you're asking. TraitDefinitions are the assets used to define traits, so you should be able to use the AssetDatabase to find the ones you've created in your project.
     
    eugolana likes this.
  46. eugolana

    eugolana

    Joined:
    Mar 27, 2019
    Posts:
    6
    Thanks, I think that's put me on the right path. Sorry if it was a naive question!
     
  47. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    Not naive! Simply unexpected.
     
    eugolana likes this.
  48. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    43
    Would there be any way to get 1 on 1 help with this system? I'd love to hash it out here, but I fear I do not know where to start and would need aid than a forum. Idk if Unity personally helps devs as such or not.
     
  49. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    87
    Feel free to message me directly!
     
    dannyalgorithmic likes this.
  50. Djayp

    Djayp

    Joined:
    Feb 16, 2015
    Posts:
    92
    Hello ! Can we hope for an update in the next two weeks ? Will traits already be decoupled ?
     
    cdm456852 and vx4 like this.
unityunity