2021-09-28 13:33:00 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "SmartObjectComponent.h"
|
|
|
|
|
#include "GameFramework/Actor.h"
|
|
|
|
|
#include "SmartObjectSubsystem.h"
|
|
|
|
|
#include "VisualLogger/VisualLogger.h"
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
|
|
|
|
#include "Engine/World.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
USmartObjectComponent::USmartObjectComponent(const FObjectInitializer& ObjectInitializer)
|
|
|
|
|
: Super(ObjectInitializer)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void USmartObjectComponent::OnRegister()
|
|
|
|
|
{
|
|
|
|
|
Super::OnRegister();
|
|
|
|
|
|
2021-11-02 11:12:43 -04:00
|
|
|
const UWorld* World = GetWorld();
|
2021-09-28 13:33:00 -04:00
|
|
|
if (World == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
|
|
|
|
// Do not process any component registered to preview world
|
|
|
|
|
if (World->WorldType == EWorldType::EditorPreview)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (HasAnyFlags(RF_ClassDefaultObject))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-26 15:48:13 -05:00
|
|
|
/** Do not register components that don't have a valid definition */
|
|
|
|
|
if (!IsValid(DefinitionAsset))
|
2021-11-02 11:12:43 -04:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 13:33:00 -04:00
|
|
|
// Note: we don't report error or ensure on missing subsystem since it might happen
|
|
|
|
|
// in various scenarios (e.g. inactive world)
|
|
|
|
|
if (USmartObjectSubsystem* Subsystem = USmartObjectSubsystem::GetCurrent(World))
|
|
|
|
|
{
|
|
|
|
|
Subsystem->RegisterSmartObject(*this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void USmartObjectComponent::OnUnregister()
|
|
|
|
|
{
|
|
|
|
|
Super::OnUnregister();
|
|
|
|
|
|
2021-11-02 11:12:43 -04:00
|
|
|
const UWorld* World = GetWorld();
|
2021-09-28 13:33:00 -04:00
|
|
|
if (World == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
|
|
|
|
// Do not process any component registered to preview world
|
|
|
|
|
if (World->WorldType == EWorldType::EditorPreview)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (HasAnyFlags(RF_ClassDefaultObject))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-26 15:48:13 -05:00
|
|
|
/** Do not register components that don't have a valid definition */
|
|
|
|
|
if (!IsValid(DefinitionAsset))
|
2021-11-02 11:12:43 -04:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 13:33:00 -04:00
|
|
|
// Note: we don't report error or ensure on missing subsystem since it might happen
|
|
|
|
|
// in various scenarios (e.g. inactive world, AI system is cleaned up before the components gets unregistered, etc.)
|
|
|
|
|
if (USmartObjectSubsystem* Subsystem = USmartObjectSubsystem::GetCurrent(World))
|
|
|
|
|
{
|
|
|
|
|
Subsystem->UnregisterSmartObject(*this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FBox USmartObjectComponent::GetSmartObjectBounds() const
|
|
|
|
|
{
|
|
|
|
|
FBox BoundingBox(ForceInitToZero);
|
2022-01-07 14:28:06 -05:00
|
|
|
|
2021-09-28 13:33:00 -04:00
|
|
|
const AActor* Owner = GetOwner();
|
2022-01-07 14:28:06 -05:00
|
|
|
if (Owner != nullptr && DefinitionAsset != nullptr)
|
2021-09-28 13:33:00 -04:00
|
|
|
{
|
2022-01-07 14:28:06 -05:00
|
|
|
BoundingBox = DefinitionAsset->GetBounds().TransformBy(Owner->GetTransform());
|
2021-09-28 13:33:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BoundingBox;
|
|
|
|
|
}
|