I think you should first get around to know the system before you start using it in an non-orthodox way. Coding behavior trees directly in C++ is not advised - that’s why we created the editor, because coding it would be too much of a hassle.
However, if you insist od creating BTs in code looks at BTTest.cpp, it’s where some of out BT unittests live - this should get you going, but I believe you’ll have hard time doing anything non-trivial.
I need your with help writing AI logic in c++ after watching few official UE4 AI tutorials. The reason I ask help is because I have spent one and a half day for looking information about the neccessary classes from the documentation and it hasn´t helped me.
First I want to mention that I am not very familiar how AI in code works, but I want to learn to code rather than use blueprints. I´ve spent too much time looking up for documentation and it´s not that self-explanatory. It also seems that people usually don´t write code when creating AI in UE4 (they partially use both - code and blueprints), so I haven´t been able to find help on the internet.
The most struggling part so far has been BehaviorTree.
According to this video tutorial the default root node of the UBehaviorTree isn´t the actual root and I should add composite selector node to it which then becomes the root. Now, it should be possible to add children to the nodes, but I find this very confusing. as the default root node (UBTCompositeNode type), only allows me to add FBTCompositeChild nodes (F stands for struct). At the same time there´s class UBTComposite nodes (_Selector, _Sequence and _SimpleParallel). I think I am missing something crucial and don´t completely understand the architecture there.
I don´t know whether the description of my problem is consistent, but maybe you could guide me with the concept of AI creation in C++. The overall problem might seem dumb, but I had nothing else in mind to get help.
Thanks for your answer.
I think I needed to hear this straight from the expert (the part that everything shouldn´t be done in c++).
When I watched the video, you created all the logic in the editor using blueprints. However, are there any good practices when creating AI - which part of the AI could and should be created directly in C++ and which part should be done via blueprints?
As I see it, the flow of the AI could be more easily surveyed/debugged when the behaviorTree is created by using blueprints.
I am sorry to ask another question in this thread, but I also encountered this weird problem now after following the same tutorial. I managed to get c++ and blueprint AI version almost working. When I debug it, my behaviortree isn´t running.
I might be mistaken, but I think [this unanswered thread] might be associated with this same problem.
I am abit clueless about that, because I´ve tried to start the tree in two different ways (in BeginPlay and Possess functions):
AAIController function - RunBehaviorTree(Character->BehaviorTreeAsset);
UBehaviorTreeComponent function - BT_Component->StartTree(*Character->BehaviorTreeAsset, EBTExecutionMode::Looped);
Here´s the info about debug view and BehaviorTreeAsset that I´ve set to Character is in the next picture with message - STEPS BACK: -1:
Hey Janyx. I think I found out that AI creation should be split between c++ and blueprints, so I decided to work with Blackboards and BehaviorTrees in the blueprints editor;
the AICharacter and AAIController logic I decided to do via writing C++.