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"

Transferring over from BP to C++ (AI)


I have a relatively general question about how to transfer over AI in Blueprints to AI in C++. I have been messing around with these awesome tutorials found HERE and I have gotten to the part where I have the four main parts of AI set up and working. But I was wondering, if I wanted to turn this into C++ code, how would I go about doing that?

I right now have AI that can: use the Behavior Tree, the Black Board Component, can move to a TargetPoint, can sense the player, can attack the player, pretty much the whole nine. But that is in Blueprints, and while I know it's powerful, I would like to to things in C++ instead.

How would I go about doing this? How could I set up the AI? How could I have it use the Behavior Tree/Blackboard? How can I use Services to make the AI properly follow along the Nodes in the Behavior Tree? How can I get it to move to a Target Point, or Sense the player, or Attack the player? Is this even possible through C++, or is this even recommended?

Basically, I would like some basics on getting this same kind of AI, that I created in Blueprints, for C++. But I don't really know where to begin (the Engine looks like a beast, and to be honest, I'm a little intimidated by it). Mind you I am using 4.6, I've heard there were some changes between pre 4.6 and after in the C++ realm. I've Googled and found A tutorial on this...The only problem is that none of the code seems to work for me (could it have been created on an older version of UE4?). Either way, I'm pretty much lost, I don't see much documentation for anyone interested in creating AI in the C++ side, and without knowing any basics of how everything works together on the C++ side, you can imagine how discouraging it could get.

Could anyone help me figure this out?


Product Version: Not Selected
more ▼

asked Feb 26 '15 at 04:25 AM in C++ Programming

avatar image

10 1 2 4

avatar image PaulJoe21 Feb 27 '15 at 06:00 PM

Hey, I have another question. Let's say I wanted to have a base C++ script for AI (not to use whole-heartedly, but something I could use for future implementation of any specialized AI code). It's based off the AIController class, but for some reason, when I try to create a BP from the script, it doesn't show up.

Why am I not seeing this code? Am I doing something wrong here?

avatar image PaulJoe21 Feb 27 '15 at 06:37 PM

Scratch that, figured it out.

avatar image lumbabumba Mar 16 '15 at 07:51 PM

I would love to see something like "set your AI complete in C++" too but the documentation is not enough here.

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

2 answers: sort voted first

My personal opinion is that if you should not try to do your AI fully in C++, especially if it's based on blueprints. Instead, you should try to know exactly what needs to be computed in C++, implement it in C++, and then expose it to the blueprint system.

For example, let's suppose you want to have a very complex function computeNextGoal that takes in input an array (for example, all the features of your AI character : its location, health, ammo, etc...) does some heavy computation that needs C++ (for example, you need to compute a matrix inversion, it would be stupidly hard and inefficient to do it in blueprint. In C++, you just use a library). So, you create a static function like described here, and inside your decorator/service/task, you call this function.

Now, why did I recommend NOT to do behavior trees in C++? Because you are going to lose the single greatest tool that UE4 Editor offers you : the visualization of your BT. Not only will your BT be much clearer to visualize, you will also be able to debug it live (with the yellow arrows)

more ▼

answered Feb 26 '15 at 07:57 AM

avatar image

56 5 10 13

avatar image PaulJoe21 Feb 26 '15 at 04:38 PM

Hmmm...But what if you want to try to base your AI in C++? Would the better option still be to use C++ to set up BP? I'm asking this because I am a programmer (obviously) and I am coming from Unity (where if you want anything done in it, you'd have to program...A lot) and I'm trying to figure out where to draw the line on when/how C++ programming is even needed for the AI.

avatar image mikepurvis Feb 26 '15 at 04:49 PM

You can always add a new C++ class extending the appropriated BehaviorTree component that you need later if you need a function to be done in C++. Then rebase the Blueprint to extend from your new C++ class which only adds the functions you need. You don't need to start with it.

Having the visual editor for BehaviorTrees is an swesome tool. In UE3 I did BehaviorTree's and imported an xml file which decribed the tree. It's much easier in a visual editor, especially one that gives you the debugging info where you can see the execution flow in real time instead of just stepping through it in a text editor.

avatar image Fezvez Feb 26 '15 at 06:48 PM

Agreed with this comment. Because that's what I actually do. I have a planner (Hierarchichal Task Network) done in C++. But I still use Behavior Trees. I just call my C++ functions at the relevant places.

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

Can't really help you too much,but you might try this tutorial https://www.youtube.com/watch?v=VxvahnKYB8E if you haven't already . I've just been making my own "AI" via C++ but it's pretty basic.

more ▼

answered Feb 26 '15 at 06:44 AM

avatar image

447 35 21 53

avatar image PaulJoe21 Feb 26 '15 at 07:53 AM

lol. That was the tutorial that I mentioned (the one where the code didn't work and left me in this confused state).

On a good note, I decided to snoop around, and I have to thank the devs at Epic. I made/opened up the C++ Flying project, and it helps a TON when they included their explanations on what's going on when I built the project. I'm right now in a bit of a quandary of what to do.

I am looking at documentation now for the UBrainComponent, I see it has the UBlackboardComponent. What's the difference between the two? Could I use UBrainComponent instead of UBlackboardComponent to store the "memory" of the AI?

I want to create (basically Drone Flying AI atm, but it could help in Enemy AI as well). AI that basically goes from TargetPoint to TargetPoint. I'm thinking UPathFollowingComponent for this...But I don't EXACTLY know how it works (does it allow Beizier movements from TP to TP? How could one implement that once the AI reaches a TP?)...

Still a ton of questions, but at least I THINK I'm getting somewhere with this (...I think)...

avatar image Fezvez Feb 26 '15 at 08:05 AM

If you see a UBrainComponent, it's in fact a UBehaviorTreeComponent. UBrainComponent is the parent of all the "AI components", but in practice, it's an abstract class with only one child : UBehaviorTreeComponent.

avatar image PaulJoe21 Feb 26 '15 at 04:44 PM

Makes sense. I guess I was a little bit confused on it. Thanks for the info!

avatar image spazchicken Feb 26 '15 at 08:52 PM

I finished it, if you ever want to try that tutorial again, I can help you with it. I was stumped like 3 times on that thing because of the new engine build, but figure everything out :)

avatar image PaulJoe21 Feb 26 '15 at 10:09 PM

Hmmm...I guess I could try to give it another shot. Would it be okay to PM you with any questions? (don't know how long this question would be up now that i've selected an answer)

avatar image spazchicken Feb 27 '15 at 08:08 AM

sure! Though how do you do that?

avatar image Fezvez Feb 26 '15 at 10:33 PM

Hey, if you figure out how to make it work and don't mind giving a short explanation, don't hesitate to put it somewhere public, like the unreal forums. Just explain where you got stumped, that would be super useful!

avatar image spazchicken Feb 27 '15 at 08:11 AM

Are you talking about that tutorial or the op question?

avatar image Fezvez Feb 27 '15 at 08:25 AM

The tutorial thing.

avatar image spazchicken Mar 01 '15 at 11:41 AM

Ok will do

(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