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?