#22, Fix crash in StaticMeshCollection
This commit is contained in:
parent
4a7b934d96
commit
8132b5fdb1
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue