I’m studying AI tutorials to find out how to simply move an NPC or AI character towards a location (or other actor). So far I’ve seen lots of Blueprint tutorials that simply use the “AI MoveTo” node in order to move their characters. I’m attempting to do this in C++, but I can’t figure out what the correct syntax (headers and functions) I need to access in order to use the equivalent “MoveTo” function.
I currently have an NPC Actor with an attached script derived from the UActorComponent. Is it possible to access or “possess” the AI for this NPC character in order to use the AI MoveTo function?
What header files do I need, and what syntax/functions will set up the C++ script to access these AI functions?
So I made an over-arching AIController C++ script called “MyAIController2”. In my NPC’s character Blueprint, I set the “AI Controller Class” option to be using my “MyAIController2” script.
Then from a separate script on the same NPC character, I’m trying to reference the AI Controller script instance, and call the MoveToActor function from it.
Am I referencing/casting the MyAIController2 script properly from my other script? Here is what I have:
But everytime my main character gets within a certain distance (and triggers the NPC character to move towards him), the editor crashes. I think maybe because I’m not properly making a subclass – but I don’t know how to make a subclass to plug into the “MoveToActor” function that comes with the AI Controller class.
What is the proper way to get a Navigation Filter to plug into the MoveToActor function?
Maybe I’m close, and maybe I’m way off…I just don’t know.
Oh that’s interesting. I didn’t even know you could do that. So, now I’m just wondering what is the “UObject* WorldContextObject” parameter? What should I (or could I) plug into that parameter?
All the other parameters make sense to me, and I should be able to plug into. But I don’t know what the WorldContextObject is supposed to be.
Thanks for the reply!
Forgot to ask as well, if there’s a function with a set of parameters, and I want to simply leave those parameters un-plugged, what do I put for those? Is it a “nullptr” or “NULL” or something like that? In Blueprints you simply don’t plug any wires into those parameter nodes…but what is it for C++?
Also, you wouldn’t happen to know how to implement the “Success” and “Failure” outputs from the path call would you?
UPDATE: It works!! Thank you so much. That is so cool. I’m still curious about some of my questions in the previous post I made though (about the null parameters, and the success or failure of the path etc.)…but I got it to work overall. My enemies now walk towards me. Thank you.