JarkkoPar / Utility_AI_GDExtension

This repository contains the binaries and example project for the Utility AI GDExtension.
MIT License
72 stars 2 forks source link

`action_node` is always null in `action_changed` signal #11

Closed madeleineostoja closed 8 months ago

madeleineostoja commented 8 months ago

I might be using it wrong, but I have actions setup for each of my behaviors and attaching a listener to the action_changed signal on the ai agent gets called when the behavior changes, but the action_node argument to the signal is always null, so I can't check for name and execute the appropriate code.

Should I be using behavior_changed instead? Seems odd if I have to update is_finished etc on actions themselves

JarkkoPar commented 8 months ago

Try adding a call to update_current_behaviour() to your AI agent, after you have the call to evaluate_options(), for example:

$UtilityAIAgent.evalute_options(delta)
$UtilityAIAgent.update_current_behaviour()

If you have only a single action for each behaviour, then you can just use the Behaviour Changed signal and it is enough to call the evaluate_options() method to choose between behaviours.

And thank you for asking, I'll add some tutorials to clarify these details with examples!

madeleineostoja commented 8 months ago

Gotcha, thanks! And I should still be setting is_finished on actions even if there’s only one per behavior?

JarkkoPar commented 8 months ago

In general, yes.

Setting is_finished=true is telling the AI agent that what ever you were doing with the action is now done and that it is OK to go to the next action. Or if this was the last (or only) action for the Behaviour, then it is OK to check for another Behaviour.

The ”Can be interrupted” property of the Behaviours has an effect on this. By default it is currently true, which means that the evaluate_options() call can check if some other Behaviour has gotten a better score than the current one even if the current one still is not finished with its actions. If you set ”Can be interrupted” to false, evaluate_options() will not check the other behaviours until the current Behaviour is finished with its actions.

Having a habit of setting is_finished=true makes sure everything works with more than one action and when the ”Can be interrupted” property needs to be set to false for some Behaviour.

madeleineostoja commented 8 months ago

Ahh okay that makes sense, thanks! For my use case most behaviors should probably not be interruptible by the agents own ai (attacking, dodging, etc) so I’ll be sure to update that and set action states accordingly