Reference to a component for another component

I think that what vivalavladislav was trying to know, based on the mention of Unity’s SerializedField, is if it’s possible to add a reference, in the Details panel, to a certain component that belongs to a world actor.

I was able to do it by declaring a reference to the actor and the type of component to get.

UPROPERTY(EditAnywhere)
ACustomActor* ActorReference;

UPROPERTY(EditAnywhere)
TSubclassOf<class USceneComponent> TypeOfComponent;

These should now appear on the Details panel. Then, based on your GetComponentByClass suggestion, I did this:

UCustomComponent* comp = Cast<UCustomComponent>(ActorReference->GetComponentByClass(TypeOfComponent));

It works! :slight_smile: However, I’m still looking for better alternatives and perhaps a way to get a specific component reference if an actor has multiple components of the same type (like colliders). I wish to avoid getting all such components (using GetComponentsByClass) and then using their string names to differentiate them, though that might not be possible…