How do i call the function GatherInstancesOverlappingArea() of UHierarchicalInstancedStaticMesh ?

I need to call this function from an actor that i made.
The reason i need to call it is because im rebuilding the function
GetInstancesOverlappingSphere
with some differences, (which is a different function that includes the GatherInstancesOverlappingArea().

I dont know if instead of that i could override it, but im not very experienced yet in overriding functions, so im just making a function that looks almost exactly like it:

However when i do, it doesnt detect the GatherInstancesOverlappingArea() as part of the HISM.
What should i do?

Function that im trying to make:


TArray<int32> AHISM_Test::GetInstancesOverlappingSphere_M(const FVector& Center, float Radius, bool bSphereInWorldSpace, UHierarchicalInstancedStaticMeshComponent* HISMToCheck) const
{
		///

		TArray<int32> Result;
		FSphere Sphere(Center, Radius);

		FBox WorldSpaceAABB(Sphere.Center - FVector(Sphere.W), Sphere.Center + FVector(Sphere.W));
		if (bSphereInWorldSpace)
		{
			Sphere = Sphere.TransformBy(HISMToCheck->GetComponentTransform().Inverse());
		}
		else
		{
			WorldSpaceAABB = WorldSpaceAABB.TransformBy(HISMToCheck->GetComponentTransform());
		}

		if (HISMToCheck->GetStaticMesh() != nullptr)
		{
			const float StaticMeshBoundsRadius = HISMToCheck->GetStaticMesh()->GetBounds().SphereRadius;
			HISMToCheck->GatherInstancesOverlappingArea(*this, WorldSpaceAABB, 0,
				[Sphere, StaticMeshBoundsRadius](const FMatrix& InstanceTransform)->bool
				{
					FSphere InstanceSphere(InstanceTransform.GetOrigin(), StaticMeshBoundsRadius * InstanceTransform.GetScaleVector().GetMax());
					return Sphere.Intersects(InstanceSphere);
				},
				Result);			
		}
		return Result;
	}
	else
	{
		return Super::GetInstancesOverlappingSphere(Center, Radius, bSphereInWorldSpace);
	}
}

Breaks at :

HISMToCheck->GatherInstancesOverlappingArea()

It says:
E0135 class “UHierarchicalInstancedStaticMeshComponent” has no member “GatherInstancesOverlappingArea”

Though in HierarchicalInstancedStaticMesh.h it has the function there.

Hi SophiaWolfie,

GatherInstancesOverlappingArea() is actually a static function.

What you can do is copy-paste it into your project just before your GetInstancesOverlappingShere_M method. (If it gives errors, just rename it, and it’s call to itself.)

1 Like

That fixed it. Thank you.

1 Like