Find TSubclassOf in TArray

Is it possible to check whether a TArray contains a type of TsubclassOf (the same object as in the array of couse), by using the FindItemByClass function?
Or is there a better way to check this?
Manually looping through and comparing is an option, albeit not a good one.

Only way I’ve made it “work”, is by letting FindItemByClass search for the parent class… which, of course, returns true every time… which is less that ideal…

I appreciate your help : )


I’m using version 4.10

I found one way of doing it.

I could use ContainsByPredicate and pass a lambda with the object itself as a parameter.
then return the comparison of the object with the Subclass. Here’s what I mean:

Class::Func(TSubclassOf<UObject> ObjectClass)
{
    Array.ContainsByPredicate
    (
       [&](const UObject* Object)
       {
          return Object->GetClass() == ObjectClass;
       }
    )
}

I guess this solves the problem, but If you have a way of doing it using FindItemByClass, please let me know : )

1 Like