UE5笔记-NavMesh的小Tips
rt.笔记备查.
Q.Runtime下动态更新navmesh所生成的RecastMesh相关的配置项参数:
放置NavVolume后会动态生成recastmesh对象
如果需要在runtime模式下实时动态更新修改可以参照下例:
UNavigationSystemV1 *subSys = UNavigationSystemV1::GetNavigationSystem(World); for (ANavigationData* data :subSys->NavDataSet) { if(auto recast = Cast<ARecastNavMesh>(data)) { { //例子测试,随机设置AgentRadius[50,100] recast->AgentRadius = FMath::RandRange(50,100); } //重新计算当前recast recast->RebuildAll(); ///重新计算指定Box区域的Namesh //recast->RebuildDirtyAreas(); //更新回调委托 //recast->OnNavMeshUpdate } } //从新刷新全部的NavDataSet //UNavigationSystemV1::GetNavigationSystem(World)->Build(); //生成完毕后的回调.会传入完成的NavDataSet //subSys->OnNavigationGenerationFinishedDelegate
Q.中止已经在运行的SimpleMoveToActor或SimpleMoveToLocation:
参考源码的UAIBlueprintHelperLibrary::GetPathComp和UAIBlueprintHelperLibrary::SimpleMoveToLocation函数的实现:
首先加入AIModule到插件或project的build.cs
可以这样子中断moveTo*:
void AMyLibrary::StopNavMoving(const UObject* WorldContextObject,AController* controll) { if (controll) { UPathFollowingComponent* PFComp = nullptr; const AAIController* AIController = Cast<AAIController>(controll); if (AIController) { PFComp = AIController->GetPathFollowingComponent(); } else { // No AI Controller means its a player controller, most probably moving using SimpleMove PFComp = controll->FindComponentByClass<UPathFollowingComponent>(); } if(PFComp->GetStatus() == EPathFollowingStatus::Moving) { PFComp->AbortMove(*controll, FPathFollowingResultFlags::OwnerFinished | FPathFollowingResultFlags::ForcedScript); } } }
本文原创,不定时更新
可以随意转载到任何网站
~但是~ 转载也要按“基本法”
请注明原文出处和作者