Non-Pawn Actor with AI controller & Movement Component

Hello everybody,

I have a question, maybe a noob question but I need to know before I go too in depth with my game. I’m making an RTS game in which the base class of every units and buildings is Actor.

After doing the building part and checking that everything is working fine with the inheritance, i’ve decided to do the unit part. But I came across a very deep conception problem, which is : unless I am wrong, I do need an AI controller to use moving functions from WheeledVehicleComponent (for tanks and trucks) and CharacterMovementComponent for infantries. BUT, as I’m using Actor as a base class, I can’t get a controller from that.

And even tho I could, I cannot inherit from both “PlayerUnit” and “WheeledVehicle”. I’m really in a dead-end here, if you guys have a solution, I would love to hear it !

the SelectableActor is a class where I put the health, max health, health bar (widgetComponent), the owner of the actor (which commander owns it) and create the mesh component of the actor (without loading anything, of course). SelectableActor split into PlayerActor and CivilianActor (which is not represented on the drawing). PlayerUnit contains stuff like the speed of the unit.

The only way I see is by duplicating a lot of code for multiple “blood lines”. For instance, doing a Building line with their own health, MaxHealth, etc, and do the exact same thing for another lane, let’s say the infantries. So that Buildings could be simple actors while infantry could start from Characters. That’s insanely dirty but I cannot think of another way :confused:

I guess there is not much to do but to refactor all my stuff.

The workaround is to use an interface that can be used as a cast identifier : Before, I was casting to SelectableActor to check and add the actors to the selected actors array (typical RTS box selection). Now, I cast my Actor as the interface. So any class that implements that interface will be concidered clickable (health bar showing up for instance).

Instead of using one main class, I use a Pawn line for my buildings (because turrets will need an AI controller and BT), Characters for my Infantries and probably WheeledVehicle for my tanks. Those 3 main lines of inheritance will implement the interface so they all can be concidered as clickable by the selection box.

I did the Building line already, and it seems to work really fine.

Oh man ! casting an actor to the Interface type actually works ! i almost had redone the whole thing again because of this ! u r great !