Assigning controllers in local multipalyer

I’m making a local multiplayer card game. I have the game working as a single player game but i’m curious how i would go about to add another player.

As of now i have all the player variables stored in the Playercontroller. Is there a way i can easily assign a controller to a a different player, giving them access to all the variables from the controller?

Hi Betag

Player Controllers are only accessible by the owning client, even on server side.

Inside the Game Mode class there is an event called “OnPostLogin” which is called each time a controller is registered with the server. Use this event to assign whatever data you need to the connecting clients.

If you want to share data between player controllers (such as names, score, lives etc), you will need to implement the Player State class (owned by the player controller). Set what data you want in this class on the server and it will be visible to all clients by accessing the “Players” array inside the Game State class.

Hope this helps.

Alex

Thanks for your answer, I’m doing Local multiplayer so i don’t think this apply.

Hi Betag

Whether it’s through Steam sessions, listen servers or dedicated servers, the rules of networking and replication apply.

but i’m curious how i would go about
to add another player.

You find out when there is a new controller (second player) in the world through the Game Modes “OnPostLogin” event (that is its purpose).

The rest of my answer was just advice about how to pass information between clients. There will be a player controller for each entity in the level, player controllers are not shared.

Maybe i’m telling this wrong. But the game has Round and i want to alternate between 2 players playing on the same PC. Each round i wanna change the player so i can get their variables.

I had a working prototype where i had 2 variables for each player, mana player 1 and mana player 2 and so on. This get very cluttered. I’m wondering if i can somehow get a controller for each player and access their variables.

So if I load up my game with just no controllers plugged in, then I plug in a second controller, the “OnPostLogin” event will fire?