关于UNavigationSystem过时的问题,针对当前此课程给出的解决方案:
#include "AIEnemy.h"
#include "NavigationSystem.h"
void AAIEnemy::OnPossess(APawn *InPawn) {
Super::OnPossess(InPawn);
Bot = Cast<AEnemy>(InPawn);
}
void AAIEnemy::OnMoveCompleted(FAIRequestID RequestID, const FPathFollowingResult &Result) {
}
void AAIEnemy::SearchNewPoint() {
// 获取导航系统
UNavigationSystemV1* NavMesh = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
if (NavMesh) {
const float SearchRadius = 1000.0f; // 搜索半径
FNavLocation RandomPt; // 随机位置
// 判断是否能找到该位置
const bool bFound = NavMesh->GetRandomReachablePointInRadius(Bot->GetActorLocation(), SearchRadius, RandomPt);
if (bFound) {
// 移动到获取的随机位置点
MoveToLocation(RandomPt);
}
}
}
在Build.cs源文件中,找到
PublicDependencyModuleNames代码,在数组中添加“NavigationSystem”
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "NavigationSystem" });