How can I grab a particular component off of a root component?

I am trying to grab the Static Mesh Component off of my root Component, which I am doing right now by using GetChildernComponents which returns all Children. Then I go through all of the components looking for there name to match up, EX: SM is the StaticMesh Component. I However would like to look for them by there type and not by a name. I tried IsA(), but I could never find the right parameters for it to Run. So my question is, if I have an array of all Child components how do I check the type of them so that I can use an if/switch statement to stop at the Component that is the StaticMesh, Or the Collider,ETC. Also is there a way to query the RootComponent for a particular Component by type.

hi,
you didn’t say what your root class is, but assuming it is ACharacter you could maybe use these methods ?

	virtual UActorComponent* FindComponentByClass(const UClass* Class) const OVERRIDE;

	template<class T>
	T* FindComponentByClass() const
	{
		return AActor::FindComponentByClass<T>();
	}

they are both defined in ACharacter.h and if they aren’t what you need maybe you can take a look what those methods do and implement a variation of them.
Hope that helps :slight_smile:

Chrys

This is what I need, however I seem to be unable to get it right, but would the Parameter for the function be, it says that OtherActor->FindComponentByClass(UStaticMeshComponent); is invalid, the error being Type name is not allowed.

You’re getting that error because you’re not passing in the right type of argument, this is what you should be doing:
OtherActor->FindComponentByClass(UStaticMeshComponent::StaticClass())