Calling to Component with an Interface

Hi there!

I am running into a bit of an architecture problem, looking for some pointers how to proceed.

Current Setup
I am making an RTS-Lite which has objects you can click on (buildings, units, etc).
All of these objects are based on a “Base Actor” class which implements an interface “Command Interface”. When you click on the actor, a Widget command panel opens up with buttons. The button panel then sends the appropriate command to the actor, via the interface, resulting in correct behaviour as the actor implements its own interfaced function.

Initial Problem to Tackle
I discovered today, that I cannot put AI on an Actor. No problem, I should have remembered this. I have set about splitting my two classes into “Base Actor” and “Base Pawn”. The rest of my project has up to this point been taking clicked actors and casting to “Base Actor” but now I run into a problem; I don’t want to (or can’t?) Cast to “Base Actor or Base Pawn”. I decided to create a component “Commandable”, which implements the interface, and is attached to both of these base classes. I painstakingly refactored so all across thee project, we are now using “Get Component by Class” instead of casting, and have a reference to the “Commandable” rather than the actor.
Only now do I discover on an old forum post that the Actor holding the Component cannot override Events from the component - I cannot implement the functions from the interface in the Base Actor / Base Pawn Class.

What to do?
I’m wondering if I missed an obvious architecture issue.

  1. I could use Event Dispatchers from the Component to the Actor - but that seems like double handling of duplicating all the functions in the interface.
  2. I could go back to initial architecture, and implement the interface on both BaseActor and BasePawn - but that is the very duplication of code that I set about to avoid when building a component. Also the question of how to cast it when getting the original reference to the clicked object, and treating it the same regardless of whether it’s BaseActor or BasePawn?
  3. Wild idea - but just as the natural engine class Pawn inherits from Actor, can I somehow restore this inheritance so that BasePawn inherits from BaseActor? But I would somehow have to get all the engine features for Pawn to be applied to BaseActor now.

Summary
Open to any ideas or questions to clarify further. Basically I’m trying to to treat my focussed object the same, regardless of whether it’s a BasePawn or Base Actor, without duplicating a lot of code across both classes. The barrier in my way seems to be that an Actor cannot override and implement its Component’s Interface Functions.

Edit
Shortly after making this post, I realize I can, with the “focussed Commandable” reference I have, → Get Owner → Execute Command. This seems to be a way to solve it; I only have one type of reference object which is “Commandable”, but am executing the Interface Functions on the Actor/Pawn instead.

Super Late but replying in case someone runs into this like I did looking for a solution.
What worked for me:

Event eg(Overlap)>Drag actor wire>Get component by interface> Select Interface>For each loop> Array Element as Target for BI- function Message. This will trigger events for all the Actor Components on an Actor with the Interface Event Implemented.

3 Likes

Thank you.