Sadly the above fails as it complains that “T template parameter to Get Components must be derived from UActorComponent” (Though UChildActorComponent does derive from UActorComponent). Is there a better way to approach this problem? Any guidance?
For those not familiar, this is called passing by reference, in the sense that the function receives your TArray and fills it for you, but only with components that match the type that you supply in the template parameter.
Given your example you might also be interested in this variant!
/* 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;
It works great if I use the “UStaticMeshComponent” as you did but fails when I use “UChildActorComponent”. Its odd as they both derive from UActorComponent.
I also just discovered that as the UChildActorComponent is being assigned though the “Add Component” at the blueprint level its not being found as a child in C++.