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. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question AI Planner - Trait not supported in this plan

Discussion in 'AI & Navigation Previews' started by Noxalus, Oct 12, 2020.

  1. Noxalus

    Noxalus

    Joined:
    Jan 9, 2018
    Posts:
    80
    Hello!

    I have an action in which I want to use a custom effect that checks if a specific trait exists on one of the parameters and does something if it's the case. The problem is that this trait is not explicitly used in the action or in any action of the plan, and when I execute the action with the custom code I get this error:

    So I tried to reproduce the problem on a smaller project by creating a Test trait, aTestPlan with a TestAction that uses a custom TestEffect with this code:

    Code (CSharp):
    1. using Unity.AI.Planner.DomainLanguage.TraitBased;
    2. using Generated.AI.Planner.StateRepresentation.TestPlan;
    3. using Generated.AI.Planner.StateRepresentation;
    4.  
    5. public struct TestEffect : ICustomActionEffect<StateData>
    6. {
    7.     public void ApplyCustomActionEffectsToState(StateData originalState, ActionKey action, StateData newState)
    8.     {
    9.         TraitBasedObjectId testObjectId = newState.GetTraitBasedObjectId(action[0]);
    10.         TraitBasedObject testObject = newState.GetTraitBasedObject(testObjectId);
    11.  
    12.         if (newState.HasTraitOnObject<Test>(testObject))
    13.         {
    14.             // Do something
    15.         }
    16.     }
    17. }
    It compiles without issue, but at runtime, if I use the TestPlan on my agent, I get this error:

    Does it means we have to explicitly use the corresponding trait in the plan somewhere else to reference it in a custom effect? Is there another way to make it work? (a way to force the trait to be known by any plan?)

    Thank you in advance for your help!
     
    Last edited: Nov 25, 2020
    DrBoum likes this.
  2. DrBoum

    DrBoum

    Joined:
    Apr 19, 2020
    Posts:
    26
  3. DrBoum

    DrBoum

    Joined:
    Apr 19, 2020
    Posts:
    26
    Edit i found a solution. this happen when a trait is requested on an active semantic query(with decision controller) and not present in any action parameters used by a specific plan.
    The solution is to add that trait on an action's parameter that the plan is using or add a new action with this trait in the parameters
    @Noxalus
     
  4. mplantady_unity

    mplantady_unity

    Unity Technologies

    Joined:
    Jun 19, 2019
    Posts:
    49
    For now, the best workaround is to include it somewhere in your actions (could be in an action parameter requirement)
    We plan to add a list of traits that you want to add manually in a plan state (via the Problem definition asset), for this issue.
     
    Noxalus likes this.