Getting actor location into BT Task?

Hi,

I have read the tutorials and the existing questions on this but am still unable to work out how to get the actor location within an AI task. The GetActorLocation fails due to the behaviour tree not being part of the level (the initial values are never updated); however, given that the majority of AI/path-finding is based around the location of actors in a level, this makes little sense.

I have tried to get the actor itself to update a key in the blackboard using a sequence of casts but this does not work.

What is the method to get dynamic data into the task of a behaviour tree? Most of the examples and videos use static data basic on way points or destinations that are static.

Any help would be much appreciated.

Thanks,

It seems you’re trying to get AI’s blackboard from a Pawn. Unless you manually added a BlackboardComponent to your pawn it doesn’t have one. Get your blackboard straight from the AIController you have. Also, while at it, the Owner Actor you get with Event Receive Execute in BT tasks is also an AIController, unless you do some advanced stuff.

And as a comment: for movement try using BT move tasks, supplied with the engine. When you use them most of the issues get solved for you and you only need to worry about putting your destination into your blackboard.

Cheers,

–mieszko

Well, if the unreal-ai-tutorial says you can use pawn then you can use pawn :smiley: Just looked at the code and it turns out pawn is a special case, the blackboard is being taken from the controller anyway.

BT has access to actor, for example you’re getting one as Owner Actor in your task’s Event Receive Execute. But yeah, as a general design rule you shouldn’t put data into your Blackboard from inside the BT tasks. You can, but it’s asking for trouble down the line.

I’m not sure what your problem is. I guess it’s that putting data into Blackboard as a response to OnComponentBeginOverlap doesn’t work. Your setup look correctly, so the bug is in the details. Just debug it (like mousing-over pins when debugging a BP shows you current value of that pin). Make sure casts have expected result, and that blackboard component is not None and the BT is being run for your AI.

Thanks for the update; the blackboard from the pawn came from this UE4 page http://unreal-ai-tutorial.info/
It is the destination value to put into the movement task that is the issue I am having. It seems that the actors have to update the blackboard with the values as the BT Tasks do not have access to the actors; this comes from How do I get references to target points or trigger volumes into Behavior Tree Service or Task graphs? - Programming & Scripting - Epic Developer Community Forums

Have found that in order to GetActorLocation for a physics object then the physics component must be the root component. When the root component is now the physics component, the GetActorLocation works within the BT Task. While this answers the question, can anyone provide an answer as to why, given the response to a previous question (How do I get references to target points or trigger volumes into Behavior Tree Service or Task graphs? - Programming & Scripting - Epic Developer Community Forums) stating that the actor location should not be available?

Thanks; the enum setting did work, was just being reset before the debug printed it out; d’oh.
Really appreciate the help, has really pushed things along :slight_smile:

It’s not good for performance, the system is designed that you update variables such as location with a BT Service. You can set a timer on those so it is not happening every tick. The BT Service will update the BlackBoard and the BT Task should use the Blackboard.