Download

Show component in actor including inheriting components

Hello,

today I’ve been trying to create an actor that shows a component of a specific class in the Details panel. I know this works something like this:


    UPROPERTY(Category = Color, VisibleAnywhere, BlueprintReadOnly, Instanced, meta = (AllowPrivateAccess = "true"))
    UColoredActorBaseComponent* ColoredActorComponent;

But instead of adding the component in the C++ constructor, I want to be able to show any component that inherits from the given base component in the details panel. The idea is to allow adding subclassed components to blueprints and showing them directly on the actor. But unfortunately this only works partially in Unreal. What I’ve done is I’m scanning for a component in the Construction and assign it to the variable, which works so far:


void AColoredActor::OnConstruction(const FTransform& Transform)
{
    AActor::OnConstruction(Transform);

    if (ColoredActorComponent == nullptr || ColoredActorComponent->IsBeingDestroyed())
    {
        UActorComponent* component = FindComponentByClass(UColoredActorBaseComponent::StaticClass());
        ColoredActorComponent = Cast<UColoredActorBaseComponent>(component);
    }
}

Very simple so far. When I select the object initially, everything is fine. But when I change anything on the Actor, suddenly the details panel behaves in a strange way and assumes I’m editing multiple components. I have attached screenshots to make it clearer with before -> after:

Deselecting the actor and selecting the actor again solves the problem, but changing anything results in the issue described above. So currently, after changing something, I have to deselect and select the actor every time again. This seems like an bug to me.
Another interesting thing to note: If I don’t add the component in the blueprint, but instead add in to the actor placed in the world, it works as I would expect. No issues whatsoever. This is an issue that only occurs when the component is added directly to the blueprint.

Thanks in advance,

yellowpaper