Files
UnrealEngineUWP/Engine/Source/Runtime/NavigationSystem/Private/NavModifierVolume.cpp
Mieszko Zielinski 167345c8eb Fixed NavModifierVolume not updating navmesh upon undoing changes in the editor
#jira UE-57115
#rb none

[CL 6663464 by Mieszko Zielinski in Dev-Framework branch]
2019-05-29 09:38:42 -04:00

99 lines
2.6 KiB
C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "NavModifierVolume.h"
#include "NavigationSystem.h"
#include "NavigationSystemTypes.h"
#include "AI/NavigationModifier.h"
#include "NavAreas/NavArea_Null.h"
#include "NavigationOctree.h"
#include "Components/BrushComponent.h"
#include "AI/NavigationSystemHelpers.h"
#include "Engine/CollisionProfile.h"
//----------------------------------------------------------------------//
// ANavModifierVolume
//----------------------------------------------------------------------//
ANavModifierVolume::ANavModifierVolume(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, AreaClass(UNavArea_Null::StaticClass())
{
if (GetBrushComponent())
{
GetBrushComponent()->SetGenerateOverlapEvents(false);
GetBrushComponent()->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
}
}
void ANavModifierVolume::GetNavigationData(FNavigationRelevantData& Data) const
{
if (Brush && AreaClass && AreaClass != FNavigationSystem::GetDefaultWalkableArea())
{
FAreaNavModifier AreaMod(GetBrushComponent(), AreaClass);
Data.Modifiers.Add(AreaMod);
}
}
FBox ANavModifierVolume::GetNavigationBounds() const
{
return GetComponentsBoundingBox(/*bNonColliding=*/ true);
}
void ANavModifierVolume::SetAreaClass(TSubclassOf<UNavArea> NewAreaClass)
{
if (NewAreaClass != AreaClass)
{
AreaClass = NewAreaClass;
FNavigationSystem::UpdateActorData(*this);
}
}
void ANavModifierVolume::RebuildNavigationData()
{
FNavigationSystem::UpdateActorData(*this);
}
#if WITH_EDITOR
void ANavModifierVolume::PostEditUndo()
{
Super::PostEditUndo();
if (GetBrushComponent())
{
GetBrushComponent()->BuildSimpleBrushCollision();
}
FNavigationSystem::UpdateActorData(*this);
}
void ANavModifierVolume::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
static const FName NAME_AreaClass = GET_MEMBER_NAME_CHECKED(ANavModifierVolume, AreaClass);
static const FName NAME_BrushComponent = TEXT("BrushComponent");
Super::PostEditChangeProperty(PropertyChangedEvent);
const FName PropName = PropertyChangedEvent.Property ? PropertyChangedEvent.Property->GetFName() : NAME_None;
if (PropName == NAME_AreaClass)
{
FNavigationSystem::UpdateActorData(*this);
}
else if (PropName == NAME_BrushComponent)
{
if (GetBrushComponent())
{
if (GetBrushComponent()->GetBodySetup() && NavigationHelper::IsBodyNavigationRelevant(*GetBrushComponent()->GetBodySetup()))
{
FNavigationSystem::UpdateActorData(*this);
}
else
{
FNavigationSystem::OnActorUnregistered(*this);
}
}
}
}
#endif