How to use GetComponents with TSubclassOf?

The error you are seeing is that you are giving a wrong type: UActorComponent instead of a UBrushDynamicComponent


 
   TArray<UBrushDynamicComponent*> Comp;
    GetComponents<UBrushDynamicComponent>(Comp);


This should compile just fine, doesn’t it?
You probably had something like:


TArray<UActorComponent*> Comp;

Now, I am not quite sure why you are getting zero components: I am not actually testing the code now, but I have used it before. Would you try adding UBrushDynamicComponent (and not a subclass) to check if that’s the issue?
Also make sure you are calling the function in the correct actor, AFTER the initialization of the components (say, add the component in the Constructor and call the function in begin play: just for testing purposes, if this is not what you want )

2 Likes