How to iterate UClasses?

I want to iterate through all UClasses with a specific parent but I’m not sure how. I need to check their properties for something I’m making these classes will not always exist as objects in the world. How can I get a list of UClasses without their corresponding classes being created?

I’ve tried passing the Name of the parent class in GetAssetsByClass on the AssetRegistry module…but it returns nothing and I tried creating an ObjectLibrary, both don’t work :(. I figured AssetRegistry would work as it looks like how it gets the class list back in the editor when you create blueprints, but I can’t find any C++ classes using this method.

I have same exact problem. I can get all assets, no problem. But I can’t get an array of specific objects using GetAssetsByClass, I always get an empty container.

Simply do:


for (TObjectIterator<UClass> It; It; ++It)
{
      // Whatever ...
}

Don’t forget to include :


#include "EngineUtils.h"

2 Likes

Note that TObjectIterator only works for loaded objects. Any UObjects (and by extension, UClasses) that are not loaded will not be part of the iterator.

1 Like

I need to get all the inheritors of the class.
The following code works as I need it.

 //Without this line, the necessary classes are not found
const auto obj = UAction::StaticClass()->GetDefaultObject();

for (TObjectIterator<UClass> It; It; ++It)
{
	if (It->IsChildOf(UAction::StaticClass()))
	{
		UE_LOG(LogTemp, Error, TEXT("UAction: %s"), *It->GetName());
	}
}

Do I understand correctly that GetDefaultObject() loads all inheritors of the class? Or in some cases, my code may not work as I expect?