本文整理汇总了C++中UNavigationSystem::TestPathSync方法的典型用法代码示例。如果您正苦于以下问题:C++ UNavigationSystem::TestPathSync方法的具体用法?C++ UNavigationSystem::TestPathSync怎么用?C++ UNavigationSystem::TestPathSync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UNavigationSystem
的用法示例。
在下文中一共展示了UNavigationSystem::TestPathSync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GeneratePathTo
bool UNavigationComponent::GeneratePathTo(const FVector& GoalLocation, TSharedPtr<const FNavigationQueryFilter> QueryFilter)
{
if (GetWorld() == NULL || GetWorld()->GetNavigationSystem() == NULL || GetOuter() == NULL)
{
return false;
}
// Make sure we're trying to path to the closest valid location TO that location rather than the absolute location.
// After talking with Steve P., if we need to ever allow pathing WITHOUT projecting to nav-mesh, it will probably be
// best to do so using a flag while keeping this as the default behavior. NOTE:` If any changes to this behavior
// are made, you should search for other places in UNavigationComponent using NavMeshGoalLocation and make sure the
// behavior remains consistent.
// make sure that nav data is updated
GetNavData();
const FNavAgentProperties* NavAgentProps = MyNavAgent ? MyNavAgent->GetNavAgentProperties() : NULL;
if (NavAgentProps != NULL)
{
FVector NavMeshGoalLocation;
#if ENABLE_VISUAL_LOG
UE_VLOG_LOCATION(GetOwner(), GoalLocation, 34, FColor(0,127,14), TEXT("GoalLocation"));
const FVector ProjectionExtent = MyNavData ? MyNavData->GetDefaultQueryExtent() : FVector(DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL, DEFAULT_NAV_QUERY_EXTENT_HORIZONTAL, DEFAULT_NAV_QUERY_EXTENT_VERTICAL);
UE_VLOG_BOX(GetOwner(), FBox(GoalLocation - ProjectionExtent, GoalLocation + ProjectionExtent), FColor::Green, TEXT_EMPTY);
#endif
if (ProjectPointToNavigation(GoalLocation, NavMeshGoalLocation) == QuerySuccess)
{
UE_VLOG_SEGMENT(GetOwner(), GoalLocation, NavMeshGoalLocation, FColor::Blue, TEXT_EMPTY);
UE_VLOG_LOCATION(GetOwner(), NavMeshGoalLocation, 34, FColor::Blue, TEXT_EMPTY);
UNavigationSystem* NavSys = GetWorld()->GetNavigationSystem();
FPathFindingQuery Query(MyNavData, MyNavAgent->GetNavAgentLocation(), NavMeshGoalLocation, QueryFilter);
const EPathFindingMode::Type Mode = bDoHierarchicalPathfinding ? EPathFindingMode::Hierarchical : EPathFindingMode::Regular;
FPathFindingResult Result = NavSys->FindPathSync(*MyNavAgent->GetNavAgentProperties(), Query, Mode);
// try reversing direction
if (bSearchFromGoalWhenOutOfNodes && !bDoHierarchicalPathfinding &&
Result.Path.IsValid() && Result.Path->DidSearchReachedLimit())
{
// quick check if path exists
bool bPathExists = false;
{
DECLARE_SCOPE_CYCLE_COUNTER(TEXT("Pathfinding: HPA* test time"), STAT_Navigation_PathVerifyTime, STATGROUP_Navigation);
bPathExists = NavSys->TestPathSync(Query, EPathFindingMode::Hierarchical);
}
UE_VLOG(GetOwner(), LogNavigation, Log, TEXT("GeneratePathTo: out of nodes, HPA* path: %s"),
bPathExists ? TEXT("exists, trying reversed search") : TEXT("doesn't exist"));
// reverse search
if (bPathExists)
{
DECLARE_SCOPE_CYCLE_COUNTER(TEXT("Pathfinding: reversed test time"), STAT_Navigation_PathReverseTime, STATGROUP_Navigation);
TSharedPtr<FNavigationQueryFilter> Filter = QueryFilter.IsValid() ? QueryFilter->GetCopy() : MyNavData->GetDefaultQueryFilter()->GetCopy();
Filter->SetBacktrackingEnabled(true);
FPathFindingQuery ReversedQuery(MyNavData, Query.EndLocation, Query.StartLocation, Filter);
Result = NavSys->FindPathSync(*MyNavAgent->GetNavAgentProperties(), Query, Mode);
}
}
if (Result.IsSuccessful() || Result.IsPartial())
{
CurrentGoal = NavMeshGoalLocation;
SetPath(Result.Path);
if (IsFollowing() == true)
{
// make sure ticking is enabled (and it shouldn't be enabled before _first_ async path finding)
SetComponentTickEnabledAsync(true);
}
NotifyPathUpdate();
return true;
}
else
{
UE_VLOG(GetOwner(), LogNavigation, Display, TEXT("Failed to generate path to destination"));
}
}
else
{
UE_VLOG(GetOwner(), LogNavigation, Display, TEXT("Destination not on navmesh (and nowhere near!)"));
}
}
else
{
UE_VLOG(GetOwner(), LogNavigation, Display, TEXT("UNavigationComponent::GeneratePathTo: NavAgentProps == NULL (Probably Pawn died)"));
}
return false;
}