Getting Instances overlapping Sphere function not working?

I am generating Hierarchical Instanced Static Mesh (HISM) instances winth C++, and I’m also trying to detect them using the inbult function GetInstancesOverlappingSphere(), but this function does not seem to work. Minimum working example is below:

UWorld* const World = GetWorld(); // Get world
	if (!World) return int32(1);

	// Just prep
	FVector spawnLocation = FVector(0.f, 0.f, 0.f); 
	FRotator rotator = FRotator(0.f, 0.f, 0.f);
	FActorSpawnParameters spawnParams;
	FTransform InstanceTransform;
	InstanceTransform.SetLocation(FVector::ZeroVector);
	InstanceTransform.SetRotation(FQuat::Identity);
	InstanceTransform.SetScale3D(FVector(1., 1., 1.));
	
	// These are defined in the editor, as public UPROPERTIES. These work fine elsewhere.
	if (!ISM_Object) return int32(1);
	if (!SuperMesh) return int32(1);

	// Spawn the actor. This is just a boilerplate AActor class right now.
	AISM_Host* host = nullptr;
	host = World->SpawnActor<AISM_Host>(ISM_Object, spawnLocation, rotator, spawnParams);
	host->SetActorEnableCollision(true); // Thought this might make a difference?
	
	// Create HISM component
	auto ISMComp = NewObject<UHierarchicalInstancedStaticMeshComponent>(host);
	ISMComp->RegisterComponent();
	ISMComp->SetStaticMesh(SuperMesh);
	host->AddInstanceComponent(ISMComp);

	// Add three instances, near the origin.
	InstanceTransform.SetLocation(FVector(0., 0., 0.));
	ISMComp->AddInstance(InstanceTransform);
	InstanceTransform.SetLocation(FVector(10., 10., 10.));
	ISMComp->AddInstance(InstanceTransform); 
	InstanceTransform.SetLocation(FVector(-10., -10., -10.));
	ISMComp->AddInstance(InstanceTransform);

	// Now we try and find them
	TArray<int32> ids = ISMComp->GetInstancesOverlappingSphere(FVector(0., 0., 0.), 100., true);

	UE_LOG(LogTemp, Warning, TEXT("Found %i HISMS"), ids.Num());

So I’m essenitally creating three instances at the origin, +10,10,10 and -10,-10,-10. These appear in world. I then try to find them with the aformentioned function, with the aim of finding the indexes of those instances within the sphere of radius 100, centred on the origin. This returns the array length of 1, everytime, no matter how many instances I add.

What am I missing here? I would expect this to return an array of length 3. Does the GetInstancesOverlappingSphere function not work?

it may be instance data can not update at 1st frame when UHierarchicalInstancedStaticMeshComponent is created, I print log in actor “beginPlay” and actor "tick "

// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
	Super::BeginPlay();

	UWorld* const World = GetWorld(); // Get world
	if (!World) return;

	// Just prep
	FVector spawnLocation = FVector(0.f, 0.f, 0.f);
	FRotator rotator = FRotator(0.f, 0.f, 0.f);
	FActorSpawnParameters spawnParams;
	FTransform InstanceTransform;
	InstanceTransform.SetLocation(FVector::ZeroVector);
	InstanceTransform.SetRotation(FQuat::Identity);
	InstanceTransform.SetScale3D(FVector(1., 1., 1.));
	host = World->SpawnActor<AActor>(spawnLocation, rotator, spawnParams);
	host->SetActorEnableCollision(true);

	// Create HISM component
	MyTestCpt = NewObject<UHierarchicalInstancedStaticMeshComponent>(host);
	MyTestCpt->RegisterComponent();
	MyTestCpt->SetStaticMesh(MyStaticMesh);
	host->AddInstanceComponent(MyTestCpt);

	// Add three instances, near the origin.
	InstanceTransform.SetLocation(FVector(0., 0., 0.));
	MyTestCpt->AddInstance(InstanceTransform);
	InstanceTransform.SetLocation(FVector(10., 10., 10.));
	MyTestCpt->AddInstance(InstanceTransform);
	InstanceTransform.SetLocation(FVector(-10., -10., -10.));
	MyTestCpt->AddInstance(InstanceTransform);

	// Now we try and find them
	TArray<int32> ids = MyTestCpt->GetInstancesOverlappingSphere(FVector(0., 0., 0.), 100., true);

	UE_LOG(LogTemp, Warning, TEXT("Begin play ---Found %i HISMS"), ids.Num());

}

// Called every frame
void AMyActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	if (MyTestCpt != nullptr)
	{
		// Now we try and find them
		TArray<int32> ids = MyTestCpt->GetInstancesOverlappingSphere(FVector(0., 0., 0.), 100., true);

		UE_LOG(LogTemp, Warning, TEXT("Tick Found %i HISMS"), ids.Num());
	}

}

293425-123545.png

you can call UHierarchicalInstancedStaticMeshComponent API -----BuildTreeIfOutdated,refrersh data at once
MyTestCpt->BuildTreeIfOutdated(false, true);

293426-11111111.png

This makes perfect sense, thank you!