Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Creating game AI in c++ instead of using blueprints


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.

Best wishes

Product Version: UE 4.16
more ▼

asked Jul 12 '17 at 10:37 PM in C++ Programming

avatar image

129 7 11 23

avatar image Janyx Jul 13 '17 at 10:08 PM

Are you looking to break ties with Behavior Trees and Blackboards too?

avatar image Rasponien Jul 13 '17 at 10:15 PM

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++.

I apologize, if I didn´t answer to your question.

avatar image Janyx Jul 13 '17 at 10:49 PM

That is definitely the UE4 blessed method. I would look at the ShooterGame example to see a great implementation of an AI. Good luck!

avatar image MieszkoZ STAFF Jul 14 '17 at 05:30 PM

For the record, ShooterGame AI is seriously outdated. Redoing it is on our todo list, but it's a really long list :/

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.



more ▼

answered Jul 13 '17 at 12:38 AM

avatar image

MieszkoZ STAFF
7.3k 223 57 412

avatar image Rasponien Jul 13 '17 at 09:55 AM

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.

Best wishes

avatar image Rasponien Jul 13 '17 at 10:03 PM

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:alt text alt text

capture1.png (330.0 kB)
capture.png (112.9 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question