C++ | Reading COM port information, pawn and update actors rotation

Hello! Im new to Unreal Engine and i’m trying to understand all the concepts used in this little world. I have read a lot but I’m still a little bit confused, so I am asking for some advice on the structre of the code.

I have a microcontroller connected to the COM port sending information about board angles (each board has an ID number). So the thing I have to achieve is, read this information and update the rotation of all boards in the level. If a new board is detected, i should spawn a new board, and if no information of a board is sent in the last two seconds, that board must be destoyed.

For this simple behaiviour is it ok to implement an APlayerController to read the port, and be the responsible of controlling boards spawning/destroying??
Any little help will be much apreciated!!

Have a nice day,
Tobías

What you outlined is fine for something simple. I’ve done several projects with a TCP backend that controls the world objects. We did it this way:

  • GameInstance: has a persistent TCP connection (you may not need to be persistent)
  • GameMode: ticks and reads incoming info from the TCP connection
  • MessageRegistry: instantiated in the GameMode on BeginPlay(), registers with the back end, and handles farming out message to specific objects

Yes it’s OK but it’s probably not the best way/place. I’d need a little more info on what you’re trying to do to give better suggestions. But I’d create a ComBoardManager object who’s job it is to watch the com port and manage in game boards. It’s job would be to create/remove/update boards as needed. Then either keep a reference to it in a custom GameInstance or a custom LocalPlayer. My personal preference is use the GameInstance for server authoritative objects but use the LocalPlayer if data is going to be passed to client->server replicated objects.