i am working on a unit selection freature, and have
URTSSelectable : public UActorComponent
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category = “RTS Selection”)
void OnSelected();
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category = "RTS Selection")
void OnDeselected();
};
but when i got an actor BP have this AC attached, actor can’t implement the AC methods OnSelected, but i subclass use Selectable subclass URTSSelectable , it will show in the Selectable event graph. so what’s wrong? just because actor is not subclass of AC?
how can i override functions in actor? i hate AC → getOwner → cast to → call function, cast to is so bad.
You can’t override the functions from one class inside another class.
I would say it depends on the use case as to whether or not this is bad design. Some times you can’t get away from it. For instance, I believe the CharacterMovementComponent is tightly coupled to the ACharacter pawn which means you can’t use the component on other actors.
That said, I tend to prefer to decouple those things which is what I believe you’re after. One way I accomplish this is to use an interface. That way the actor component doesn’t have to know what kind of actor it’s attached to. I simply call the interface function and if the owning actor implements it then great, otherwise nothing happens.
thank you for answer, my final solutions is use interface to decouple. thought the TypedScriptInterface trouble me a lot. thank you.