Best way to control pawns from a player?

I would like to have chess pieces (and any non-player actor/pawn) do something when they are selected. I got some ideas, but I don’t know which is best:

  1. Pawn gets possesed by player controller - problem: camera switches and player isn’t controlled anymore
  2. Player saves pawn instance as variable when it’s selected and sends an event call/message to the instance on the desired action
  3. Player sends a message to all instances of class and only selected instances (that have Selected = true) react - possible problem: slow
  4. Maybe AI-Controller but it’s for when a pawn acts on it’s own. Don’t think that’s it. It’s supposed to react directly to input.

It’ll probably involve Blueprint Interface and either idea 2 or 3.

Yellow = selected:

Every chess piece is constructed in the same class. Think, that’s easier than have a pawn class for every piece type, way easier to access:

Selection works from player perspective. Works as it should:

Only one piece can be selected at a time and selecting 1 pieces deselects all other selected. That works too:

I tackled almost same problem some time ago. I wanted tactical squad game where player controlled 1 out of 4 members of a squad (remaining 3 followed controlled one).

However it was 4.15 or so (maybe there are new better ways now):

  • i created Camera Pawn for player. That was camera manager and hud/widgets only.
  • then AI controlers for all squad members. Really simple AI, that could move short distance, shoot enemy and change formations.

For your game it would be even simpler to control chest pieces. And logic again suggest that player is just camera and gui, while pawns are AI controlled pieces.

2 Likes

Hey there @Knampf1! I agree with Nawrot in that your implementation could definitely be simplified a bit.

From a high level:

  • Player is just a camera, a GUI, and a selection manager under the hood.
  • Instead of looping through the pieces, you can just check the class or tag on your the object you hit with the trace.
  • Instead of controlling the pawns directly or using AI you could just use an interface to just send the event to the pawn to move to a location.
1 Like

“Player is camera and checking hit object” That’s what I wanted to do. The hit object is saved as a Chess Piece variable in PlayerCharacter. On every click, Player also sends a message via Blueprint Interface to the selected chess piece (that we saved with 1 of previous clicks). The event called is in the chess piece class and only executes when piece is selected. Then you can set whatever the piece is supposed to do within the chess piece class itself.
Is that the best way?
Wasn’t sure how multi-pawn is usually done.

One step further (Well few more steps):

  • use game play tags, to name pieces, like “piece.pawn.01, piece.queen.01, etc”. Then name sides like “side.white, and side.black”
  • create single actor that is just chess piece. It shoud have above gameplay tag, set by you, and know tiles where they are. It should change apperance based on gameplay tag. But make apperance only as inherited class. So parent class has game logic, child class has apperance.
  • now make dispatcher in game mode or something easily accessible. It should tell pieces who moves where. Like gameplay tag = piece.pawn.01 and side.white. and how it moves.
  • create function that given “adress” like A4 gives location (and reference to that tile) of center of that tile
2 Likes