Search code examples
c++unreal-engine4

How can I get a List of all UClasses in the project (Blueprint and C++)


I want to get a list of all UClasses.

I tried to search in ClassViewer but it gives me a SWidget so I don't know how can I get an UUserWidget* from it.

 FClassViewerModule& ClassViewerModule = FModuleManager::LoadModuleChecked<FClassViewerModule>("ClassViewer");
 FClassViewerInitializationOptions initClassViewer = FClassViewerInitializationOptions();
 FOnClassPicked onClassPicked = FOnClassPicked();
 TSharedRef<SWidget> classesWidget = ClassViewerModule.CreateClassViewer(initClassViewer, onClassPicked);

If I can't get an UUserWidget* from that SWidget then, is there another way to get a list of all UClasses that are currently created in the project?

EDIT

I just want to get a list of UClasses so I can put it in a widget ComboBox, I thought that if I get an UUserWidget from "classesWidget" then I could get the values of UClasses (they should be inside a PanelBox), but what I really need is to get the list, it doesn't need to be an UUserWidget, that question was because I found that method.


Solution

  • I finally just put a TObjectIterator so I can get every class I want:

        for (TObjectIterator<UClass> It; It; ++It)
        {
            if (It->IsChildOf(AActor::StaticClass()) || It->IsChildOf(APawn::StaticClass()) || It->IsChildOf(ACharacter::StaticClass()))
            {
                actorClasses.Add(*It);
            }
            else if (It->IsChildOf(USceneComponent::StaticClass()))
            {
                componentClasses.Add(*It);
            }
            else if (It->IsChildOf(UUserWidget::StaticClass()))
            {
                widgets.Add(*It);
            }
        }