My lovely AI character didn't move?

I had went through the AI and behavior trees documents in unreal website. But i didn’t really comprehend the concepts introduced there. So i made a very very simple project to see whether the AI module will work.
I did steps below but in the end, it didn’t work…

1.Create two classes: AIController and Character.
2.Add “AIModule” in my XXX.Build.cs.
3.Add a property of class UBehaviorTree to my Character and set a BehaviorTree to it in the UnrealEditor.
4.Add property of UBehaviorTreeComponent and UBlackboradComponent to my AIController, and initialized them:


AMyAIController::AMyAIController()
{
	this->bbc = CreateDefaultSubobject<UBlackboardComponent>("bb");
	this->btc = CreateDefaultSubobject<UBehaviorTreeComponent>("bt");
}

5.Overriden the Possess() method to initialize the Blackborad of Character, set a simple location to it and StartTree.


void AMyAIController::Possess(APawn* in)
{
	auto ai = Cast<AMyAICharacter>(in);
	if (ai != nullptr)
	{
		if (ai->bt->BlackboardAsset)
		{
			this->bbc->InitializeBlackboard(*(ai->bt->BlackboardAsset));
			this->bbc->SetValueAsVector(FName("TargetLocation"), FVector(-10, 20, 448));
			this->bbc->SetValueAsObject(FName("SelfActor"), ai);

		}
		this->btc->StartTree(*(ai->bt));
	}
}

6.Compiled the code, create BehaviorTree and Blackbroad in content browser and set corresponding attributes to them.


7.Set AIContorllerClass to Character.
无标题.png
7.Add a NaviMeshBoundVolume, and the land true green.
8.Dragged a Character to level and play.
9.I can see the engine passed through all the nodes in BehaviorTree, but my character just stood still and did nothing…
无标题.png

I think i must miss some points, so it did’t work. But i can find where i’m wrong.

Did you build after placing the nav mesh? If you do an AI controller Move To an actor, does it work?

Thanks for replying!
And yes, i built it, the ground turn green too.
I tried to use a method same as Move To in c++ (since i’m not good at blueprint)
like this:


void AMyAIController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	
	EPathFollowingRequestResult::Type temp = this->MoveToLocation(FVector(340, 320, 50));
	if (temp == EPathFollowingRequestResult::Type::Failed)
	{
		GEngine->AddOnScreenDebugMessage(0, DeltaTime, FColor::Red, FString("Failed"));
	}
}

And the return value of MoveToLocation is “Failed”. So there must be something wrong besides AI module, maybe Navigation module. But what is it… i can’t find out.

Maybe the location is unreachable?
Try placing some actor (for example waypoint) on the map in the editor and use the same location in your code.
If u are using the map template, this TargetLocation seems unreachable to me (Z = height, so your target location is 448 in the air?)

You are right, that is one of the problem. But there still have some more because the return value of MoveToLocation(FVector(340, 320, 50)) is “Failed”. (this time the location is reachable)
The engine tells me that something is wrong, but does not tell me where and why. Maybe i should go through some documents about navigation.

Thanks to all the friends replied and helped me!
I finally cleared this problem! But still don’t know why…
I just created a new project, do all the things same as before and it fantastically worked, what a miracle.:inf: