Best practice for an actor component to interact with another actor component

It really depends on the design of your component. I doubt a component that adds fighting abilities would make sense if applied to a static mesh actor for example, so I don’t see a huge issue in creating a dependency between that component and a certain type of base class. If you are reliant on features of the Character, you don’t have much choice really.

As an alternative, you could create an Interface/Component combination. The actor would have to inherit from a common Interface class and would provide functions that must be implemented by the actor, then the component can interface with it’s owning actor by casting it to an interface. Interfaces work best when they are CPP-only - reflected interfaces require a lot of jumping through hoops.



class ISomeInterface
{
    virtual void SomeCommonFuction() = 0;
}

class AMyCharacter, public ACharacter, public ISomeInterface
{

}

class ASomeOtherActor, public AActor, public ISomeInterface
{

}




void UMyFightingComponent::DoSomething()
{
    ISomeInterface* TheOwner = Cast<ISomeInterface>(GetOwner();
    if (TheOwner)
    {
        TheOwner->SomeCommonFunction();
    }
}


This only works in very specific scenarios though. Again if you are dependent on Character features, there’s nothing wrong with only allowing the component to be used by a Character class.