I have a master Room object that is parented to every prop in a given room. Some of these props have a UInteraction component on them, and I’m trying to compile a TArray of every interaction component on a Room’s children. I know I can find all instances of a class in my level by running FindComponentByClass() , but is there a simple way to constrain the results such that I only ever query the children of my Room or another given Actor?
Yes, you would just need to do the check your self after the query, run your own filter.
Loop through the result, GetOwner or GetRootComponent or GetAttachParent depending on how your components are setup. Check to see the returned Parent matches the “Room Parent Actor” that you want. Add them to your Matched Array for further work.
Hope that helps =)
Thank you for the response!
Is there any chance that there’s a way to narrow the results to every child of the actor before I check for the class? One of the reasons I’m structuring it this way is because there are thousands of actors with this class across the game world, and limiting it to an actor’s children lets me iterate through 5-10 objects instead of hundreds.
Actually I took a quick look at the code base and found a version that accepts a Tag. I haven’t used this function, but it looks like you could give it a Tag to help breakout just the components for a named Actor. Hope that helps =)
/* Gets all the components that inherit from the given class with a given tag. */
UFUNCTION(BlueprintCallable, Category = "Actor", meta = (ComponentClass = "ActorComponent"), meta = (DeterminesOutputType = "ComponentClass"))
TArray<UActorComponent*> GetComponentsByTag(TSubclassOf<UActorComponent> ComponentClass, FName Tag) const;
Ooh awesome, thank you