Fix crash when reloading a saved map generator
This commit is contained in:
parent
004e2cc4c7
commit
734f0f0534
|
@ -38,12 +38,7 @@ void ACityMapMeshHolder::OnConstruction(const FTransform &Transform)
|
||||||
|
|
||||||
for (tag_size_t i = 0u; i < NUMBER_OF_TAGS; ++i) {
|
for (tag_size_t i = 0u; i < NUMBER_OF_TAGS; ++i) {
|
||||||
// Create an instantiator for each mesh.
|
// Create an instantiator for each mesh.
|
||||||
auto instantiator = NewObject<UInstancedStaticMeshComponent>(this);
|
GetInstantiator(CityMapMeshTag::FromUInt(i));
|
||||||
instantiator->SetMobility(EComponentMobility::Static);
|
|
||||||
instantiator->SetupAttachment(SceneRootComponent);
|
|
||||||
instantiator->SetStaticMesh(GetStaticMesh(CityMapMeshTag::FromUInt(i)));
|
|
||||||
MeshInstatiators.Add(instantiator);
|
|
||||||
instantiator->RegisterComponent();
|
|
||||||
}
|
}
|
||||||
UpdateMapScale();
|
UpdateMapScale();
|
||||||
}
|
}
|
||||||
|
@ -98,9 +93,8 @@ void ACityMapMeshHolder::AddInstance(ECityMapMeshTag Tag, uint32 X, uint32 Y, fl
|
||||||
|
|
||||||
void ACityMapMeshHolder::AddInstance(ECityMapMeshTag Tag, FTransform Transform)
|
void ACityMapMeshHolder::AddInstance(ECityMapMeshTag Tag, FTransform Transform)
|
||||||
{
|
{
|
||||||
auto instantiator = MeshInstatiators[CityMapMeshTag::ToUInt(Tag)];
|
auto &instantiator = GetInstantiator(Tag);
|
||||||
check(instantiator != nullptr);
|
instantiator.AddInstance(Transform);
|
||||||
instantiator->AddInstance(Transform);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
@ -110,10 +104,9 @@ void ACityMapMeshHolder::AddInstance(ECityMapMeshTag Tag, FTransform Transform)
|
||||||
void ACityMapMeshHolder::ResetInstantiators()
|
void ACityMapMeshHolder::ResetInstantiators()
|
||||||
{
|
{
|
||||||
for (tag_size_t i = 0u; i < NUMBER_OF_TAGS; ++i) {
|
for (tag_size_t i = 0u; i < NUMBER_OF_TAGS; ++i) {
|
||||||
UInstancedStaticMeshComponent *instantiator = MeshInstatiators[i];
|
auto &instantiator = GetInstantiator(CityMapMeshTag::FromUInt(i));
|
||||||
check(instantiator != nullptr);
|
instantiator.ClearInstances();
|
||||||
instantiator->ClearInstances();
|
instantiator.SetStaticMesh(GetStaticMesh(CityMapMeshTag::FromUInt(i)));
|
||||||
instantiator->SetStaticMesh(GetStaticMesh(CityMapMeshTag::FromUInt(i)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,3 +133,19 @@ void ACityMapMeshHolder::UpdateMapScale()
|
||||||
MapScale = size.X;
|
MapScale = size.X;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UInstancedStaticMeshComponent &ACityMapMeshHolder::GetInstantiator(ECityMapMeshTag Tag)
|
||||||
|
{
|
||||||
|
UInstancedStaticMeshComponent *instantiator = MeshInstatiators[CityMapMeshTag::ToUInt(Tag)];
|
||||||
|
if (instantiator == nullptr) {
|
||||||
|
// Create and register an instantiator.
|
||||||
|
instantiator = NewObject<UInstancedStaticMeshComponent>(this);
|
||||||
|
instantiator->SetMobility(EComponentMobility::Static);
|
||||||
|
instantiator->SetupAttachment(SceneRootComponent);
|
||||||
|
instantiator->SetStaticMesh(GetStaticMesh(Tag));
|
||||||
|
MeshInstatiators[CityMapMeshTag::ToUInt(Tag)] = instantiator;
|
||||||
|
instantiator->RegisterComponent();
|
||||||
|
}
|
||||||
|
check(instantiator != nullptr);
|
||||||
|
return *instantiator;
|
||||||
|
}
|
||||||
|
|
|
@ -80,6 +80,9 @@ private:
|
||||||
/// Set the scale to the dimensions of the base mesh.
|
/// Set the scale to the dimensions of the base mesh.
|
||||||
void UpdateMapScale();
|
void UpdateMapScale();
|
||||||
|
|
||||||
|
/// Creates a new one if necessary.
|
||||||
|
UInstancedStaticMeshComponent &GetInstantiator(ECityMapMeshTag Tag);
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
USceneComponent *SceneRootComponent;
|
USceneComponent *SceneRootComponent;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue