Ara you OK?
我看你是思想出现了偏差
哇!你认出了错别单词!恭喜你获得一次向我支付宝充值助我重返欧洲的机会!
这个页面管关不掉了,你自己看着办吧

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);
		}
	}
}

  

 

posted @ 2024-07-16 20:04  林清  阅读(100)  评论(0编辑  收藏  举报