Check if actor has a specific mesh component

Given an AActor* OtherActor pointer, how can I check if this actor includes a mesh component of a predefined type? (For example /Game/FirstPerson/Meshes/FirstPersonTemplateCube).

Here is a way to do this check

.h

UPROPERTY(EditAnywhere)
		UStaticMesh* TestedMesh;
	UPROPERTY(EditAnywhere)
		AActor* TestedActor;
	UFUNCTION()
	bool CheckIfActorHasStaticMesh(AActor* Actor, UStaticMesh* StaticMesh) const;

.cpp

bool ATestActor::CheckIfActorHasStaticMesh(AActor* Actor, UStaticMesh* StaticMesh) const
{
	if (Actor == nullptr || StaticMesh == nullptr) { return false; }

	TArray<UStaticMeshComponent*>  StaticMeshComponents;
	Actor->GetComponents(StaticMeshComponents);

	if (StaticMeshComponents.Num() > 0)
	{
		for (UStaticMeshComponent* smc : StaticMeshComponents)
		{
			if (smc->StaticMesh == StaticMesh)
			{
				return true;
			}
		}
	}

	return false;
}

I assume is static mesh, lets do it in for of bool function

for(UActorComponent  i : OtherActor->GetComponentsByClass(UStaticMeshComponent::StaticClass()) {

       if(((UStaticMeshComponent*) i)->StaticMesh->GetPathName().Equals("/Game/FirstPerson/Meshes/FirstPersonTemplateCube.FirstPersonTemplateCube")) return true;

}

return false;

Now problem is path, i never used GetPathName and i’m not usre if it returns same string as “Copy Refrence”, but this path for that mesh should be the same all the time for that mesh (and this is how you can detect the mesh without need to hard reference it) or else you relocate the mesh, so it case if it does not work study what GetPathName returns. You could also use GetName() but then you need to watch out to not have mesh with same name.

It works…So with getname i would only check against “FirstPersonTemplateCube.FirstPersonTemplateCube”?