You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
* Collection entry holds the Transform, Bounds and Index to the shared configuration. This removes the dependency on components being loaded to create runtime data for partitioned worlds. * Removed commented references to SparseClassData since that approach won't be used (actor component not supported) * Runtime data now points to a shared configuration from the collection instead of holding a copy * Subsystem tracks components registered at runtime so the collection can be updated accordingly since those entries won't persist outside of loading range * Moved most initialization code for the subsystem to the OnWorldComponentsUpdated callback since active level collection is set and actors from the persistent level registered. [WorldPartitionBuilder] * Added OnPartitionBuildStarted/OnPartitionBuildCompleted virtual methods * New UWorldPartitionSmartObjectCollectionBuilder to build SmartObjectCollection in partitioned worlds #preflight 61814a46fc786a0001447995 #jira UE-105113 #rb maxime.mercier #ROBOMERGE-AUTHOR: yoan.stamant #ROBOMERGE-COMMAND: FnMain #ROBOMERGE-SOURCE: CL 18019580 in //UE5/Main/... #ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v885-17909292) #ROBOMERGE[STARSHIP]: UE5-Release-Engine-Staging Release-5.0 #ROBOMERGE[bot1]: Main [CL 18019655 by yoan stamant in ue5-release-engine-test branch]
122 lines
2.7 KiB
C++
122 lines
2.7 KiB
C++
// 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
|
|
|
|
namespace FSmartObject
|
|
{
|
|
const FVector DefaultSlotSize(40, 40, 90);
|
|
}
|
|
|
|
USmartObjectComponent::USmartObjectComponent(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
|
|
}
|
|
|
|
void USmartObjectComponent::OnRegister()
|
|
{
|
|
Super::OnRegister();
|
|
|
|
const UWorld* World = GetWorld();
|
|
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;
|
|
}
|
|
|
|
/** Skip components that were duplicated to hold template configuration in the Collection */
|
|
if (IsTemplateFromCollection())
|
|
{
|
|
return;
|
|
}
|
|
|
|
// 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();
|
|
|
|
const UWorld* World = GetWorld();
|
|
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;
|
|
}
|
|
|
|
/** Skip components that were duplicated to hold template configuration in the Collection */
|
|
if (IsTemplateFromCollection())
|
|
{
|
|
return;
|
|
}
|
|
|
|
// 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);
|
|
const AActor* Owner = GetOwner();
|
|
if (Owner == nullptr)
|
|
{
|
|
return BoundingBox;
|
|
}
|
|
|
|
const FTransform LocalToWorld = Owner->GetTransform();
|
|
|
|
for (const FSmartObjectSlot& Slot : GetConfig().GetSlots())
|
|
{
|
|
const FVector SlotWorldLocation = LocalToWorld.TransformPositionNoScale(Slot.Offset);
|
|
BoundingBox += SlotWorldLocation + FSmartObject::DefaultSlotSize;
|
|
BoundingBox += SlotWorldLocation - FSmartObject::DefaultSlotSize;
|
|
}
|
|
|
|
return BoundingBox;
|
|
}
|
|
|
|
bool USmartObjectComponent::IsTemplateFromCollection() const
|
|
{
|
|
return Cast<ASmartObjectCollection>(GetOwner()) != nullptr;
|
|
}
|