Behavior Designer - how to setup AI agents to interact with buttons or doors

serkai

New member
I'm not sure of the best way to configure enemy agent AI to interact with objects such as platforms via button trigger or openable doors. I tried the stop/start ability but it did't work, any advice would be much appreciated. Thanks
 
It sounds like you are using the Ultimate Character Controller integration? For interacting with doors I actually would not have it within the behavior tree at all - you should instead set a trigger on the door which then calls TryStartAbility to start the interact ability.

If you have the Deathmatch AI Kit the air lift is a good example of this. When the character enters the trigger the ability will automatically start with TryStartAbility. When the character leaves the trigger the NavMeshAgent is warped to the current position. In this case the behavior tree didn't even know that the character used the air lift.
 
Yes I'm using the Ultimate Character Controller and Deathmatch AI Kit. I was hoping to use the behaviour tree as part of the game objectives, for example the as the first objective player or enemy must complete a task, which is the top priority, and the secondary objective is to not die / survive. The task would require the player or enemy to press and hold a button, then stop holding the button if they are attacked.
 
In that case the TryStartStopAbility is the right way to go. If the task is returning failure then the ability isn't able to start. The easiest way to debug this is to place a breakpoint within TryStartStopAbility.OnUpdate and step into what condition is making it fail.
 
Thanks Justin, do you have an example of TryStartStopAbility.OnUpdate I can look at in more detail?

Here's what I was getting previously, for both attempts / multiple trial and error configurations I get "NullReferenceException: Object reference not set to an instance of an object".

(For the playable character the button works fine)
 

Attachments

  • Screenshot 2021-01-26 at 14.41.45.png
    Screenshot 2021-01-26 at 14.41.45.png
    308.6 KB · Views: 19
  • Screenshot 2021-01-26 at 14.52.14.png
    Screenshot 2021-01-26 at 14.52.14.png
    276.2 KB · Views: 18
Your Target GameObject should be left blank. This should be a reference to the character itself.
 
Thanks Justin, I still haven't cracked this. I'm not sure where to map the press button Interactable ID / Object ID / Ability Index Parameter.

Error: Unable to find a Use ability with slot -1 and action 9
 

Attachments

  • Screenshot 2021-01-27 at 16.23.36.png
    Screenshot 2021-01-27 at 16.23.36.png
    446.2 KB · Views: 13
  • Screenshot 2021-01-27 at 16.17.28.png
    Screenshot 2021-01-27 at 16.17.28.png
    145.4 KB · Views: 11
With start stop ability the task was complete button the button wasn't triggered
 

Attachments

  • Screenshot 2021-01-27 at 17.12.21.png
    Screenshot 2021-01-27 at 17.12.21.png
    482.9 KB · Views: 8
Your first image has StartStopUse instead of StartStopAbilty so that's why you are getting the error. Beyond that your interact ability should have button down as it is an AI agent.

If it still doesn't work you should place a breakpoint within StartStopAbility.OnUpdate and step through the code to see what is returning false. There are a number of situations which can cause the task not to start.
 
I added the breakpoint for the StartStopAbility and I received this error:

Code:
In order to call GetTransformInfoExpectUpToDate, RendererUpdateManager.UpdateAll must be called first.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
 
Last edited:
You should have start ability enabled. The second error that you posted comes from Unity and is unrelated.

Your first error is going to cause some issues. For Interact to work it needs to know what object it should interact with. Since you are starting it from the behavior tree you will run into issues with m_Interactable being null. I will add a public property to Interact which allows you to set the m_Interactable variable, and from there you'll want to make sure you first set the Interactable. Maybe I need to create a new task that specifically starts the Interact ability.

This will be added to Interact.cs:

Code:
        [Shared.Utility.NonSerialized] public Interactable Interactable { get { return m_Interactable; } set { m_Interactable = value; } }

Then you'll need to create a new task which sets the property.
 
Hi Justin - it works! I think the character IK state interact was the missing culprit. I also needed to give the agent time to complete the interaction, previously the agent would wander off before the interaction animation had finished.

Thanks so much for your help!
 
Top