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

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

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

  1. Noxalus

    Noxalus

    Joined:
    Jan 9, 2018
    Posts:
    80
    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

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    118
    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

    Noxalus

    Joined:
    Jan 9, 2018
    Posts:
    80
    Thank you for your answer!

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