Instanced static mesh component added through c++ performance problem

Hi guys, I have a c++ actor which has UInstancedStaticMeshComponent added with

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = GridFloor) in header file.

I created it in constructor, and updated it in PostEditChangeProperty with 2 for loop by X and Y two integer

So the InstacedStaticMeshComponent will be a grid with xsize * ysize.

When I change the size integer to 1010 it takes almost 1~2 sec, and when i change it like 2020,

the editor freezes like 10sec.

Below is part of my code

.h File

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = GridFloor)
class UInstancedStaticMeshComponent* GridFloor;

.cpp in Constructor

GridFloor = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("GridFloor"));
GridFloor->AttachTo(Root);
GridFloor->bCastDynamicShadow = false;
GridFloor->CastShadow = false;
GridFloor->SetMobility(EComponentMobility::Static);

.cpp in PostEditChangeProperty

GridFloor->ClearInstances();

for (int x = 0; x < XSize; x++)
{
	for (int y = 0; y < YSize; y++)
	{
		FVector tmpTranslation(x*100.0f, y*100.0f, 0.0f);

		GridFloor->AddInstance(FTransform(tmpTranslation));
	}
}

I already have made same actor through Blueprint (not derive from c++ actor), and when Update it in Construction Script, it just works fine.

when i update the grid in beginPlay, it just fine but i need it in editor, not in-game

Is this a bug? or Did i wrong somewhere??

Hi Donyun Jeong
Don’ t use PostEditChangeProperty, instead use the equivalent Blueprint Construction Script in c++ is called OnConstruction:

virtual void OnConstruction(const FTransform& Transform) {}

I tried OnConstruction, but it’s same. thank you for answer.

ZkarmaKun is right. Maybe you forgot something? If you set a breakpoint in your code does it get called? Maybe need a Call to parent inside your Blueprint? Double check everything please =)

Ok, I comment out PostEditChangeProperty function, then derived a blueprint actor from my c++ class.
In that blueprint class, I setup construction script with the inherited InstancedStaticMeshCompoentn, then its same. But, i added a new ISMComponent, then use it in construction script, it works fine. instant update with 30*30 grid. dont know why

Ok, I tried even more, but it doesnt work. the OnConstruction function is called, but each AddInstance() function in OnConstruction takes too long. almost 400~900 milisec on each call.
So i deleted UPROPERTY() macro on ISMComponent in header file, then it works. don’t know why but i’ll digging from here. Thanks for reply, and sorry for my english.