How can I make a player spectate random player in multiplayer?

After a game has begun and a new player joins the session how can I make him spectate a random player?
I’m new to multiplayer coding so screenshots would really help. Thanks!

If someone reads this I came up with a solution.
Hope this helps:

First in my GameMode OnPostLogin whenever a new controller (or you can say player) joins I add him to the PC (Player controller) array.

After that I created a Custom event called Spectate which runs through all of the joined player controllers and checks for each controller if Playing bool in their player state is set to true. (When host starts the game it sets that bool to true to all of the connected players. If you join after the game has begun it will be set to false).
If it’s false it will give all of the Controllers that their Playing bool is set to false.And I set Spectate from player state to true. (So a player will not spectate other player that spectates a player, hope that makes sense :stuck_out_tongue: )
After that I kinda do the same thing get all of the Controllers that their Spectate bool from Player state is set to false (Players that are playing) and compare tags. Basically what it does it goes through lets say controller 1 checks if he spectates if he does it checks what about controller 2 if he also does it continues to other controllers, if he doesn’t it compares the tags between the spectator and the nonspectator if equal then set the spectator controller Camera blend to the non spectator.

I can’t add more pictures but lastely in my Player Controller I created a custom event that runs on server and is reliable. That event casts to the GameMode and calls the Spectate event, and that’s it for that event.
I call that event whenever a player picks a team (Clicks on button), Ofcourse before I call that custom event I check if Playing bool from player state is set to true if not then call the event. I do that by get owning player → cast to player controller → from as player controller I get player state → cast to player state → get Playing → branch → if false call the event.

Hope this helps someone understand something about spectating. I know this answer is not exactly like my question but I had to change some things to fit my game.If you have any questions or you know a better way to do spectating please do let me know.

1 Like

Thank you so much bro.Your comment helped me a lot

Players already have a Spectating variable built in (so you could use that instead of creating a Playing bool). This Spectating mode is involved with the GameMode parent class (but I think not the GameModeBase class) as the former is designed to handle situations like having players join a game and spectate at first and then not be able to spawn until the game has truly begun.