Files
UnrealEngineUWP/Engine/Source/Runtime/NavigationSystem/Private/NavMesh/NavMeshBoundsVolume.cpp
aris theophanidis 5b72c692c0 Fix navmesh not generating on the default map floor when NavMeshBoundsVolume is placed perfectly flat with the surface (which used to occur by default)
#jira UE-137292
#rb Maxime.Mercier
#preflight 61e1d91c6462b347f4c6099d

#ROBOMERGE-AUTHOR: aris.theophanidis
#ROBOMERGE-SOURCE: CL 18622649 in //UE5/Release-5.0/... via CL 18622654 via CL 18622660
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v899-18417669)

[CL 18622676 by aris theophanidis in ue5-main branch]
2022-01-14 15:25:22 -05:00

96 lines
3.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "NavMesh/NavMeshBoundsVolume.h"
#include "NavigationSystem.h"
#include "Engine/CollisionProfile.h"
#include "Components/BrushComponent.h"
#if WITH_EDITOR
#include "ActorFactories/ActorFactory.h"
#endif // WITH_EDITOR
ANavMeshBoundsVolume::ANavMeshBoundsVolume(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
GetBrushComponent()->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
GetBrushComponent()->Mobility = EComponentMobility::Static;
BrushColor = FColor(200, 200, 200, 255);
SupportedAgents.MarkInitialized();
bColored = true;
}
#if WITH_EDITOR
void ANavMeshBoundsVolume::PostEditChangeProperty( struct FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
if (GIsEditor && NavSys)
{
const FName PropName = (PropertyChangedEvent.Property != nullptr) ? PropertyChangedEvent.Property->GetFName() : FName();
const FName MemberName = (PropertyChangedEvent.MemberProperty != nullptr) ? PropertyChangedEvent.MemberProperty->GetFName() : FName();
if (PropName == GET_MEMBER_NAME_CHECKED(ABrush, BrushBuilder)
|| MemberName == GET_MEMBER_NAME_CHECKED(ANavMeshBoundsVolume, SupportedAgents)
|| MemberName == USceneComponent::GetRelativeLocationPropertyName()
|| MemberName == USceneComponent::GetRelativeRotationPropertyName()
|| MemberName == USceneComponent::GetRelativeScale3DPropertyName())
{
NavSys->OnNavigationBoundsUpdated(this);
}
}
}
void ANavMeshBoundsVolume::PostEditUndo()
{
Super::PostEditUndo();
UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
if (GIsEditor && NavSys)
{
NavSys->OnNavigationBoundsUpdated(this);
}
}
void ANavMeshBoundsVolume::OnPostEngineInit()
{
if (GEditor)
{
const TArray<UActorFactory*>& ActorFactories = GEditor->ActorFactories;
for (UActorFactory* Factory : ActorFactories)
{
// For ANavMeshBoundsVolume, do not use placement extent so that the volume embeds into the surface.
// When flush with the surface, the collision might not be in the volume and the navmesh might not generate.
if (Factory->NewActorClass->IsChildOf(ANavMeshBoundsVolume::StaticClass()))
{
Factory->bUsePlacementExtent = false;
}
}
}
}
#endif // WITH_EDITOR
void ANavMeshBoundsVolume::PostRegisterAllComponents()
{
Super::PostRegisterAllComponents();
UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
if (NavSys && GetLocalRole() == ROLE_Authority)
{
NavSys->OnNavigationBoundsAdded(this);
}
}
void ANavMeshBoundsVolume::PostUnregisterAllComponents()
{
Super::PostUnregisterAllComponents();
UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
if (NavSys && GetLocalRole() == ROLE_Authority)
{
NavSys->OnNavigationBoundsRemoved(this);
}
}