Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

AI Planner - Update the world state regularly when AutoUpdate is true?

Discussion in 'AI & Navigation Previews' started by Noxalus, Jul 16, 2020.

  1. Noxalus


    Jan 9, 2018
    Hello everyone!

    I'm currently exeprimenting the AI planner preview package (v0.2.3) and after multiple tests, I've figured out that objects with trait that are instanciated after an agent doesn't exist for this agent.

    So I've downloaded the official Unity samples and checked the Vacuum Robot example where the robot cleans dust heaps that appear after the robot to understand how it works.

    And I found this code in the VacuumRobot script:

    Code (CSharp):
    1. m_Controller.AutoUpdate = true;
    2. if (m_UpdateStateWithWorldQuery && m_Controller.PlanExecutionStatus != PlanExecutionStatus.ExecutingAction)
    3. {
    4.     m_Controller.UpdateStateWithWorldQuery();
    5.     m_UpdateStateWithWorldQuery = false;
    6. }
    The important part is the call to UpdateStateWithWorldQuery method allowing the robot to see all dust heaps that spawned since the last call.

    So my question is: why don't we update the world state each time a job is finished by default?

    This call can't be done when a job is executing, and for me there is no interface yet to know if the current job is finished.

    And in my case, checking the PlanExecutionStatus like it's done for the VacuumRobot is not enough, I get a lot of errors doing that:

  2. TrevorUnity


    Unity Technologies

    Jun 28, 2017
    Depending on how many objects are in the scene, querying can be expensive, which is why we try to do it only when necessary. You can manually trigger it via DecisionController.UpdateStateWithWorldQuery().

    Which job is preventing this? The planning jobs are forced to complete before any state queries occur.

    Have you looked at IsIdle?
  3. Noxalus


    Jan 9, 2018
    Thank you for your answer!

    The IsIdle property seems to be better than the comparison I did before, I will use that now!