Update:
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:
AMyAIController2 * AIInstance1 =
Cast<AMyAIController2>(thisCharacter);
AIInstance1->MoveTowardsActor(mainCharacterActor->GetOwner());
Here is my “MyAIController2” script:
#include "MyAIController2.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Runtime/Engine/Classes/AI/Navigation/NavigationData.h"
#include "Runtime/Engine/Classes/AI/Navigation/NavigationSystem.h"
/*AMyAIController2::AMyAIController2(const FObjectInitializer& ObjectInitializer) : Super (ObjectInitializer)
{
UNavigationSystem * NavSys = GetWorld()->GetNavigationSystem();
Filter1 = UNavigationQueryFilter::GetQueryFilter(*NavSys->MainNavData, DefaultNavigationFilterClass);
//TSubclassOf<AMyAIController2> Filter2 = Cast<Filter1>(UNavigationQueryFilter::GetQueryFilter(*NavSys->MainNavData, DefaultNavigationFilterClass);
}*/
void AMyAIController2::MoveTowardsActor(AActor* ActorTarget)
{
MoveToActor(ActorTarget, 500.0f, true, true, true, DefaultNavigationFilterClass, true);
}
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.