Files
UnrealEngineUWP/Engine/Source/Runtime/NavigationSystem/Private/NavMesh/NavMeshBoundsVolume.cpp
aris theophanidis d131f4029b Crash fix for UActorFactory::NewActorClass that can be null.
#rb Yoan.StAmant
#rb Steve.Robb
#jira UE-146444
#lockdown Nick.Whiting
#preflight 623394e3791d231e02090253

#ROBOMERGE-AUTHOR: aris.theophanidis
#ROBOMERGE-SOURCE: CL 19426688 in //UE5/Release-5.0/... via CL 19427263
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v930-19419903)

[CL 19429562 by aris theophanidis in ue5-main branch]
2022-03-17 19:09:40 -04:00

101 lines
3.1 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_EDITORONLY_DATA
bIsSpatiallyLoaded = false;
#endif
}
#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.
const TSubclassOf<AActor> ActorClass = Factory->NewActorClass;
if (ActorClass != nullptr && ActorClass->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);
}
}