Download

Get a reference of a BehaviorTree from C++

Hi Guys, i put this question in Get a reference of a BehaviorTree created inside the Editor - UE4 AnswerHub but no answers, so i put here to see if anyone from here can help me, please.

I need to get the instance of a BehaviorTree created in the Editor (using Content Browser/Misscellaneous/BehaviorTree) in my AIController class.

I created the Behavior Tree inside the editor to see the Workflow and setup graphically but i like to get a instance of this behavior tree inside my AIController extended c++ class. To do a RunBehaviorTree with this reference. How i can do this, how i can get a reference of a BehaviorTree created inside the Editor ??

I know, i can do this in AIController blueprint connecting the Begin Play node to Run behavior Tree node and select the corresponding Asset, but i like to do this in Cpp. My problem is getting the BehaviorTree instance.

I trying using

static ConstructorHelpers::FObjectFinder BehaviorTreeBPClass(TEXT(“BehaviorTree’/Game/MyBehaviorTree.MyBehaviorTree’”));

inside AIController constructor but when i run this the editor show me this Message in the log tab.

Error /Game/MyBehaviorTree: Can’t find file for asset. /Script/BehaviorTreeEditor

Info Failed to load /Script/BehaviorTreeEditor.BehaviorTreeGraph Referenced by MyBehaviorTree Property /Script/AIModule.BehaviorTree:BTGraph

Info Failed to load /Script/BehaviorTreeEditor.BehaviorTreeGraph Referenced by MyBehaviorTree Property /Script/Engine.Blueprint:EditedDocumentInfo.EditedObject

The BehaviorTree for this test only have the Root node.

Thanks and sorry for my bad english