RPC looks like it breaks SOLD practices

When my Pawn wants to interact with some Actors, the Pawn must perform the RPC for the Actor. This means that the Pawn must know something about the Actor it is interacting with in some cases.

Yes, some Interactables, like doors or switches, are simple enough that the Pawn simply tells the Server it is interacting with Actor X, and the door or switch moves by the RPC from the Server. The only RPC from the Client to the Server is “I am Interacting with X”, which doesn’t need to know what X is. But some interactions are more complicated than this simple use case.

Here is my scenario. If anyone can tell me of a better approach, I am all ears.

I have a Tank with a Seat for the pilot and a Seat for the gunner. For this reason, the tank cannot be possessed by both, so I decided it won’t be possessed by either. (I could allow the pilot to possess the tank, but this problem will still exist for the gunner.) The Tank is a Skeletal Pawn, while the two Seats are Actors wrapped as Actor Components.

The Pawn requests to sit in the gunner seat by performing an RPC to the Server saying it is “interacting with an Interactable”, which is the base class for all Actors that the Pawn can interact with. The Pawn isn’t aware of what kind of Interactable it is interacting with. Thus, it does not require changes when new Interactables are introduced. This is how it should be.

But once the Server says that the Pawn is Seated (by attaching to the Seat Actor), the Pawn is prevented from receiving gun aiming input. Those are directed to the Gunner Seat. When the Server attached the Pawn to the Seat, it also added a higher priority IMC for the Gunner Seat, which is correct both by interpreting the input for the Gunner Seat, and by keeping the logic and specifics to the Gunner Seat in the Gunner Seat. This is how it should be.

BUT!!!

When the Pawn on the Client turns the turret or raises the barrel, the RPC to the Server fails, because the Client is not the owner of the Gunner Seat. Looking around, it appears I need to some how make the Pawn do the RPC for the Gunner Seat, which means the Pawn must KNOW SOMETHING about the Gunner Seat.

SOLID principle is broken.

If I add other Interactables on this level of complexity, then each time I need to update my Pawn.

Game design complexity grows.

Thoughts on this welcomed.

Can anyone tell me if I am looking at this incorrectly?

Can I make just the Seat Actor Component owned by the Player Controller?

EDIT:

I am leaning toward a new approach, the Seat being responsible for injecting a Component specific to the Seat in the Pawn itself to handle the input events. This new Component would be able to then call into the Seat (the attached parent Actor to the Pawn) when necessary. This would keep the Pawn unaware of the Seat entirely. This approach would allow the Pawn to interact with any Interactable Actor, provide the necessary RPCs to the Server, and never require updating to support new Interactables. … now to make it work…

The approach described above worked well. I could use the Components to enhance a Pawn without the Pawn being aware it was being hijacked to do more than it was designed to do. This is what was necessary to keep the Pawn unaware and not requiring modifications when introducing new Actors to interact with, including vehicles.

The approach I used within Blueprint is not documented as a best practice, in part due to the warning found in the Add Component By Class node (which changes its name to reflect the class you are adding).

The node says it should not be called manually, but I got it working just fine. I had to set the Component to replicate and didn’t have any problems with it. I realize i should break out the C++ and follow best practices; but this is strictly a prototype.

.

To be clear the SOLID principle most offended by having to modify the Pawn for any new Interactable that comes along is described here:

Open-closed Principle (OCP) states:

Objects or entities should be open for extension but closed for modification.

This means that a class should be extendable without modifying the class itself.

The next step is to see if the driver possessing the tank will make it replicate its movements (Chaos Vehicle Movement Component) more smoothly. I would prefer a symmetrical architecture, but if the CVMC requires possession to make smooth replicated movement, then it’s gots to be.

Just wanted to add one more approach I discovered worked well.

I decided that the injected Component into the Character Pawn was not working cleanly like I wanted it to.

So I then created Pawn Seat Actors; one for the tank Pilot and another for the tank Gunner. This allowed me to possess the Seats that the Character Pawn sat in (attached to) and this in turn allowed all tank specific scripts to sit within the tank itself. The Character Pawn only “interacts” with the Seats, not knowing anything about the Seats, or even that they are Seats. All the Character Pawn knows them as is their base class, Interactable, derived from Pawn.