Can anyone point me to proper ways to work with game mode and game state?

So right now I am getting into the details of getting my UMG HUD and player controller to talk to my Game state and game mode. However the only way I have been able to get this working correctly so far has been through casting to the game state within the player controller.

This feels dirty as it appears that I wont be able to use this same player controller for different game modes.

If I can just see how to get all of these different blueprints to talk to each other it would make me feel a lot better as I am just unsure what really is the best way to do this.

Any advice on this front would be much appreciated.

What about blueprint interfaces?- YouTube
If you have not worked much with interfaces… may the force be with you.
It confused me to death in the start, but then again… i did not have any coding background.

Its easiest to see GameMode and GameState as coming in pairs, and the same for PlayerController and PlayerState. The distinction is that the -States exist on all clients in a multiplayer game whereas the GameMode and PlayerControllers don’t.

I’m assuming that you want your PlayerController to report some events to your game mode? Crocopede’s suggestion may work well then. Suppose you want your PlayerController to report deaths to the game mode. You can create an interface IPlayerDeathListener, and when a player dies his PlayerController Gets All Actors that implement IPlayerDeathListener and calls a function on them. And if one of them happens to be a game mode that implements that interface, you have your result: the game mode gets the event and your PC is still game mode independent.

Ah thanks for the info guys that makes a lot of sense to do it that way. Heck it might be better to have listeners like this for all of my cross blueprint communication actually. I have been doing a dance of casting, dispatchers functions and its been fairly complicated and messy. But telling each of my blueprints to just listen for certain things. Now that sounds way easier to deal with but I am not sure how it will be in practice.

Hmm last night I was trying to make a list of all players on the server through game state. I have an array in game state and every time a button is clicked on each client it runs a function on gamestate to add that player controller to an array. Well, the array would only count that individual client and non of the others. Every client seems to have its own array? I was scratching my head about that. I guess stuff like this needs to go into game mode?

You can’t add items to a list on a client and expect it to be added server-side as well, if that was what you’re trying. If you add entries to a replicated array client-side, that will result in the client-side array becoming out of sync with the server. To change data on the server while being a client, you have to use an RPC that is executed on the server (a client-to-server request).

What are you trying to do with the list of all players? Is it for client-side display or for server-side gameplay logic? The server has access to all PlayerControllers (the client only his own), so you don’t need to construct a list manually, just get all player controllers by index or by a GetAllActorsOf node. For client-side display, try making use of PlayerStates (all clients have these for all players), as in prepare all necessary data by setting replicated values server-side, then they are available client-side. Hope that clears things up a bit.

Here is the system I am setting up right now on my Trello Trello

What I am doing is having all players spawn into the server as spectators and each player has the option to queue up. So its like getting in line to fight. Once two or more players are ready the game grabs those player controllers and has them posses the player character and begin the match. Winner stays and the loser leaves.

So I need to make a list of each player that is ready so to speak then make sure that I remove the loser of the match and bump the others up one slot.

This list will be visible to all clients as well.

Oh holy **** for some reason I CANNOT get an interface to work correctly from player controller to player state. I simply do not know what tiny detail I am missing right now but this fairly simple concept seems to have become a total nightmare.

What is going on?

Nevermind, I figured it out and its not so bad at all. I was just missing the proper target for the game state.

Now to figure out how to generate a queue for players to join a match. hmm