CelticCraft/Plugins/VoxelFree/Source/Voxel/Private/VoxelStaticWorld.cpp

32 lines
986 B
C++
Raw Normal View History

2023-07-03 16:17:13 +00:00
// Copyright 2020 Phyronnaz
#include "VoxelStaticWorld.h"
#include "VoxelMinimal.h"
#include "Components/StaticMeshComponent.h"
AVoxelStaticWorld::AVoxelStaticWorld()
{
}
#if WITH_EDITOR
void AVoxelStaticWorld::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
if (PropertyChangedEvent.MemberProperty &&
PropertyChangedEvent.MemberProperty->GetFName() == GET_MEMBER_NAME_STATIC(AVoxelStaticWorld, BaseMesh) &&
PropertyChangedEvent.ChangeType != EPropertyChangeType::Interactive)
{
for (UStaticMeshComponent* Mesh : Meshes)
{
auto* StaticMesh = Mesh->GetStaticMesh().Get();
auto RelativeTransform = Mesh->GetRelativeTransform();
Mesh->ReinitializeProperties(BaseMesh);
Mesh->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
Mesh->SetStaticMesh(StaticMesh);
Mesh->SetRelativeTransform(RelativeTransform);
Mesh->RegisterComponent();
}
}
}
#endif