I have a HoverTank Pawn Blueprint. It knows how to hover, and how to animate its turret/cannon. I want to support multiple different tank chassis with different weapons, so I put as little as possible into this blueprint other than chassis-specific things.
I also have a HoverController, which derives from PlayerController. It knows how to receive input from players that drives the tank, as well as doing things like spawning fired projectiles etc. I put anything that’s largely the same across hovertank types into this class.
But, I’d like to also have an AIHoverController, which uses all the same mechanisms for firing missiles, hovering, applying torque for turning, etc. The only bit I want to swap out is who sends the input – players, or AI.
What’s the right way to structure this? Ideally, I’d want the HoverController to only do player input decoding, and then send off everything else to the controlled pawn, so I can re-use the pawn for AI controlled entities.
But, because I also want a number of different chassis types (that animate differently, have different weapons combinations, etc) I don’t want to put everything into the pawn.
Where do I put all the shared stuff? Controllers expect to be attached to Pawns; Pawns expect to have Controllers; and there’s no obvious intermediary between the two, because my “shared code” needs to look like a controller to the pawn, but look like a pawn to the controller.
I can’t even use that OO cop-out of deep inheritance (which I generally dislike) because I can’t insert my shared code “above” PlayerController and AIController in the hierarchy, where it would “fit” if I wanted to shoehorn this delegation stuff into inheritance.