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…
