Search code examples
c++unreal-engine4unreal-blueprint

UE4 Display Actor Components at Runtime in PIE


I create and attach some actor components at runtime and destroy them later when playing.

I would like to see during runtime in PIE what components an actor has.

I already tried to display the components by checking the Show Actor Components in the View options of the Details panel, but it seems to only display scene components, and to not refresh the view correctly (I have to check then uncheck Selected Actor Only for the spawned actor to display all their scene components).

Is there a way to do display them?


Solution

  • can you tell me you are using C++ or Blueprints ?

    If you are using C++, you can create a method to show the existing Components in your Actor. You can use the method GetComponents to get all Components of the class UActorComponent because all the Unreal Engine's components inherit from this Class. And then you can check their classes and print the name and the class for example.

    This is an example of code :

    void AMyActor::ShowMyComponents() {
        TArray<UActorComponent*> MyArray;
    
        GetComponents(UActorComponent::StaticClass(), MyArray, true);
        for (auto element : MyArray) {
            UE_LOG(LogTemp, Error, TEXT("Component  : %s is from class : %s"), *element->GetName(), *element->GetClass()->GetName());
        }
    }
    

    you can call this method for example in BeginPlay() or in Tick() or anywhere you want and it will show you the components of your actor.