Setting Task_MoveTo Blackboard Key in C++

Hi all, I’m fooling around with behavior tree and blackboards in C++, and I’m attempting to keep everything in C++ and away from visual blueprints, and everything goes well except I can’t seem to figure out how to set the blackboard key in the MoveTo task in C++. if I manually set it in the blueprint (please see the image), and everything else remains in C++ (creating sequence, tasks, blackboard, blackboard keys, etc.), everything works as expected.

I get this

UStructProperty* KeyProp = FindField<UStructProperty>(UBTTask_BlackboardBase::StaticClass(), TEXT("BlackboardKey"));
			FBlackboardKeySelector* KeyPropData = KeyProp->ContainerPtrToValuePtr<FBlackboardKeySelector>(&m);

and for some reason I’m too blind to see how to set the value :smiley:

Thanks!

I was expecting that something simple and straightforward like this would work

KeyPropData->SelectedKeyName = "TargetPointPosition";

but it doesn’t… I mean the struct updates the value properly but there’s no effect on the actual task, which still returns the field as “None”

I wonder what am I missing?..

Well, I extended the BTTask_MoveTo class and put a setter in it that directly updates BlackboardKeySelector’s SelectedKeyName and it seems to be working okay now.

Is this approach acceptable from UE4’s coding standard? Should I tackle it differently? My goal is to have the behavior tree and related items in C++ 100%, and the extended class with the setter helps accomplish this, but I would like to stick with the coding standard, please let me know your thoughts.

Thanks!

OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Object>(BlackboardKey.GetSelectedKeyID(), NewObjectValue);

this is the correct way, found it :smiley:

Hi, sorry to bother you. I have this same problem but I can’t fit you answer in my code for some reason.
I created my MoveTo task on code, now I’m trying to find a way to set the BlackboardKey in the task. Could you please put the setter you made?
Thank you in advance :).

hi, thank you for your comment, I’m sorry my previous experience is not that helpful to you. As far as I remember, I figured it out by studying %path%\Epic\UE_4.xx\Engine\Source\Developer\AITestSuite\Public\BTBuilder.h (replace with your installation path and xx with your engine subversion). it may also be worth mentioning that eventually I decided to handle BT the visual way and kept C++ only for super custom situations. Hope this helps. Thanks!