[C++] Get all subclasses of a given class without including classes prefixed with SKEL_ (skeleton classes)

I have a certain base class that I plan to extend several times into various blueprints. I am able to get the subclasses of this class using the following code:

 for(TObjectIterator<UClass> It; It; ++It)
 {
     if(It->IsChildOf(BaseClass::StaticClass()) && !It->HasAnyClassFlags(CLASS_Abstract))
     {
         Subclasses.Add(*It);
     }
 }

This works without giving any errors which is great; however, this is also including the skeleton classes of the blueprints which I do not want.

Is there any way to exclude the skeleton classes or otherwise filter them out?

PLEASE NOTE: When I am referring to skeleton classes I am talking about the the blueprint classes prefixed by SKEL_

Hey .

add another Expression which checks if *It != USkeletalMeshComponent::StaticClass()

for(TObjectIterator<UClass> It; It; ++It)
{
    if(It->IsChildOf(BaseClass::StaticClass()) && !It->HasAnyClassFlags(CLASS_Abstract))
    {
        if(*It != USkeletalMeshComponent::StaticClass())
        {
            Subclasses.Add(*It);
        }
        else
        {
            UE_LOG(LogTemp, Warning, TEXT("Found SkeletalMeshComponent. Did not add it"));
        }
    }
}

When I am referring to skeleton classes I do not mean anything to do with Skeletal meshes, rather I am referring to classes generated and used by the engine prefixed with “SKEL_” maybe I used their name incorrectly sorry if I did. I have also seen them referred to as SKEL_ assets

I’m going to edit the original question to reflect that I am referring to classes prefixed by SKEL_ sorry for the misunderstanding,

Hey .

Unfortunately Skeleton Classes don’t share the same Base Class (Except UObject but we don’t want that :P)

Fortunately you can get a String Represantation of your Classes if you call the Method GetName().
So just parsing through this String should be fine.

auto ClassName = *It->GetName();

if(ClassName.Len() > 4)
{
    if(ClassName[0] == 'S' && ClassName[1] == 'k' && ClassName[2] == 'e' && ClassName[3] == 'l')
    {
        UE_LOG(LogTemp, Warning, TEXT("This is a Skeleton Class"));
    }
}

should do the trick :slight_smile:

Good Luck

Greetings

Amazing idea thank you very much – For anyone that ever looks at this and wants to do the same thing I had to make some subtle changes instead of auto for the type of ClassName use FString and when checking the characters they should be capitalized

No Problem :slight_smile:
I’m glad I could help you

Good Luck

Do yourself a favour and check for the “REINST_” prefix as well.

You could use an FString and ToLower, if you want to be sure your comparison always works.