#22, Fix crash in StaticMeshCollection

This commit is contained in:
nsubiron 2017-04-28 14:55:20 +01:00
parent 4a7b934d96
commit 8132b5fdb1
2 changed files with 14 additions and 10 deletions

View File

@ -24,30 +24,34 @@ void AStaticMeshCollection::PushBackInstantiator(UStaticMesh *Mesh)
Instantiator->SetupAttachment(RootComponent);
Instantiator->SetStaticMesh(Mesh);
Instantiator->RegisterComponent();
MeshInstatiators.Add(Instantiator);
MeshInstantiators.Add(Instantiator);
}
void AStaticMeshCollection::SetStaticMesh(uint32 i, UStaticMesh *Mesh)
{
check(GetNumberOfInstantiators() > i);
MeshInstatiators[i]->SetStaticMesh(Mesh);
if ((GetNumberOfInstantiators() > i) && (MeshInstantiators[i] != nullptr)) {
MeshInstantiators[i]->SetStaticMesh(Mesh);
}
}
void AStaticMeshCollection::AddInstance(uint32 i, const FTransform &Transform)
{
check(GetNumberOfInstantiators() > i);
MeshInstatiators[i]->AddInstance(Transform);
if ((GetNumberOfInstantiators() > i) && (MeshInstantiators[i] != nullptr)) {
MeshInstantiators[i]->AddInstance(Transform);
}
}
void AStaticMeshCollection::ClearInstances()
{
for (auto *Instantiator : MeshInstatiators) {
Instantiator->ClearInstances();
for (auto *Instantiator : MeshInstantiators) {
if (Instantiator != nullptr) {
Instantiator->ClearInstances();
}
}
}
void AStaticMeshCollection::ClearInstantiators()
{
ClearInstances();
MeshInstatiators.Empty();
MeshInstantiators.Empty();
}

View File

@ -21,7 +21,7 @@ protected:
uint32 GetNumberOfInstantiators() const
{
return MeshInstatiators.Num();
return MeshInstantiators.Num();
}
void PushBackInstantiator(UStaticMesh *Mesh);
@ -38,5 +38,5 @@ protected:
private:
UPROPERTY(Category = "Instanced Static Mesh Collection", VisibleAnywhere)
TArray<UInstancedStaticMeshComponent *> MeshInstatiators;
TArray<UInstancedStaticMeshComponent *> MeshInstantiators;
};