No player controller on client?

Hi, I’ve been working on a multiplayer game for some time now, testing the multiplayer was always fine, but today when I wanted to test it, just the server side worked, it seems like for the clients the player controller is not being created, the pawns are being spawned and I can see them on the server side, but they don’t show on the client side and I can’t control them.
Also i get the error: accessed none trying to read the value of getPlayerController if I play as client

I have tried changing the gameMode and all the classes in it to some default ones and it doesn’t work either. Is there maybe some engine value that I could have accidentally changed that could cause this problem?

Yes, PlayerControllers are not replicated to clients because:

  1. they not really needed there as they can control pawns on server
  2. as a security measure, client should have less game state controlling power as much as possible aspecially for otherp layers, as the more client can do there more hacking potential. Not to mention any replicated data even if you not using it visually can be obtained by user by reading memory, so they can’t be secret.

Same goes with GameMode, as it is central gameplay control class and only server really needs it, there only hacking risks from doing otherwise. If i’m not mistaken only local player controllers of local player exists in client and they are replicated to server.

But both PlayerController and GameMode have replicable counterpart which allows to replicate any needed data from those classes (like game and player stats and so on which all players can access) they are called GameState and PlayerState

The problem with those are fact that they not quite usable in blueprints (yet?), most likely you will need to use C++ here, at least to make your own class which later you could use in blueprint, but you can make your own class that is replicated fully in blueprint that will have similar function, you can also store needed data in pawns which will get replicated (only problem with that is fact it will get deleted with pawn so you need to keep copy in PlayerController).

1 Like

Since this is kinda recent, just wondering if you’ve been able to figure out what you were doing wrong. I’ve got the same issue and haven’t found anything useful yet.

Thanks,

Also isn’t 2xP90 pretty excessive?

Hi, if I recall correctly I messed up the game mode blueprint, couldn’t fix it so I just created a new one and deleted the old one

And the new blueprint works fine? Weird. I have another project I’ve been comparing too where both players work fine and I can’t come up with any difference to explain it, could certainly try redoing the game mode bp.

That’s possibly because your game mode and game state class not match.
Game mode must be with game state and game mode base be with game state base.

1 Like

Important point. That did the trick for me. Thanks

Hi, I know this is old, but what do you mean “be with”? (Actually disregard that, I see what you mean I believe.)

I’m running into an issue. I servertravel to a map and the client follows me know problem. The full match works fine, and then when I try to trigger a rematch by “servertraveling” again to the same map I’m currently on, the second player controller doesn’t exist anymore.

Aside from my first question, any idea if that’s related or if I’m missing something else?

Thanks

Server travelling again is probably not the most reliable/efficient way to do a rematch since you’re already in level and all the player controllers are logged in and available. You can simply just get all actors of class and destroy them in the game mode and spawn new player characters wherever you need and have the player controllers possess them and rerun the starting logic created the first go around.

1 Like

Agreed. That is AGameModeBase::ResetLevel() and then you define how AActor::Reset() functions on the different actor classes. What @Sir_Deathbed described is calling AGameMode::RestartGame() which is okay too, but I would refrain from reloading the level again, unless there is some special case I’m not aware of.

3 Likes

Thank you that helps. I think I have a good idea of how to move forward.

1 Like

Thank you, I’m doing this in blueprints, but I suppose I could set up an event dispatcher and bind it to an event on each main actor that is a custom “reset” event.