ue5吧 关注:3,873贴子:6,910
  • 1回复贴,共1

UE5 C++ 有偿求解决

只看楼主收藏回复




输出:
LogTemp: Warning: MoveTo result: 0
LogTemp: Warning: NavPath is invalid!
为什么没有找到路径,目标点已经被导航网络覆盖了


IP属地:韩国1楼2024-11-24 15:42回复
    可能造成的原因有很多。先修改完善代码排错。
    EnemyController =Cast<AAIController>(GetController());
    if (EnemyController &&PatrolTarget)
    {
    FAIMoveRequest MoveRequest;
    MoveRequest.SetGoalActor(PatrolTarget);
    MoveRequest.SetAcceptanceRadius(15.0f);
    MoveRequest.SetCanStrafe(true);
    MoveRequest.SetUsePathfinding(true);
    // 获取路径指针
    FNavPath* NavPath = NavPathSharedPtr.Get();
    if (NavPath)
    {
    EPathFollowingRequestResult::Type MoveResult = EnemyController->MoveTo(MoveRequest,NavPath);
    UE_LOG(LogTemp, Warning, TEXT("MoveTo result: %d"),(int32)MoveResult);
    if (NavPath->IsValid())
    {
    const TArray<FNavPathPoint>& PathPoints =NavPath->GetPathPoints();
    for (auto& Point : PathPoints)
    {
    const FVector& Location =Point.Location;
    }
    }
    else
    {
    UE_LOG(LogTemp, Warning, TEXT("NavPath is invalid!"));
    // 处理路径无效的情况
    // 例如,重新计算路径或者选择新的目标
    // 这里简单地重新计算路径作为示例
    NavPathSharedPtr = EnemyController->FindPathToActor(PatrolTarget);
    if (NavPathSharedPtr.IsValid())
    {
    FNavPath* NewNavPath =NavPathSharedPtr.Get();
    MoveResult =EnemyController->MoveTo(MoveRequest, NewNavPath);
    UE_LOG(LogTemp, Warning,TEXT("Re - MoveTo result: %d"), (int32)MoveResult);
    }
    }
    }
    else
    {
    UE_LOG(LogTemp, Warning, TEXT("NavPath pointer is null!"));
    // 处理路径指针为空的情况
    // 例如,重新获取路径
    NavPathSharedPtr = EnemyController->FindPathToActor(PatrolTarget);
    if (NavPathSharedPtr.IsValid())
    {
    FNavPath* NewNavPath = NavPathSharedPtr.Get();
    EPathFollowingRequestResult::Type MoveResult =EnemyController->MoveTo(MoveRequest, NewNavPath);
    UE_LOG(LogTemp, Warning, TEXT("New MoveTo result: %d"),(int32)MoveResult);
    }
    }
    }
    定义部分改为:
    // 假设这是头文件中的定义
    class AAIController;
    class AActor;
    // 定义属性
    UPROPERTY()
    class AAIController* EnemyController =nullptr;
    UPROPERTY(EditInstanceOnly, Category ="AI Navigation")
    class AActor* PatrolTarget = nullptr;
    这样看输出结果,排查一下具体问题原因在哪。


    IP属地:吉林2楼2024-11-25 20:35
    回复