Im making generation in editor using PostEditChangeProperty, and Im not using ClearInstances anymore.
Im calculate instances number delta and add/remove them accordingly.
void UpdateInstances(TArray<FTransform>& Transforms)
{
HISMComponent->bAutoRebuildTreeOnInstanceChanges = false;
int32 InstCountDelta = Transforms.Num() - HISMComponent->GetInstanceCount();
if (InstCountDelta > 0)
{
for (int32 i = 0; i < InstCountDelta; i++)
HISMComponent->AddInstance(FTransform());
}
else if (InstCountDelta < 0)
{
InstCountDelta = FMath::Abs(InstCountDelta);
for (int32 i = 0; i < InstCountDelta; i++)
HISMComponent->RemoveInstance(HISMComponent->GetInstanceCount() - 1);
}
for (int32 i = 0; i < Transforms.Num(); i++)
HISMComponent->UpdateInstanceTransform(i, Transforms[i], false);
HISMComponent->bAutoRebuildTreeOnInstanceChanges = true;
HISMComponent->BuildTreeIfOutdated(true, true);
HISMComponent->Modify();
}
It works well if Im setting new values directly, but sometimes its crashes if Im using mouse drag to change value. And its crashing every time when trying to copy/paste that actor.
Well, Im sure Im doing something in wrong way ))
All of thus will not cras with simple ISM components, but HISM component is more useful, especially with lods for mobile.