Create Player - Work half the time.
So, I'm currently trying to make a local two player shared screen setup. Player 1 is all good, no problem. The problem is with player 2, it work ... half the time. When I play (new editor windows). half the time I do get my second player/character, half the time I do not (and it come down to the "Is Valid" being negative in that case) I have tried to delay the execution of SpawnP2, or delay right after CreatePlayer. Still got it to work half the time. It seems random, I guess it's not, is it related to my computer resources ? The order the game process something ?
PS : the current setup make use of an BlankPawn as default, that is destroy and replaced by the DF-BaseCharacter. Reason being later I will get the player to choose witch character they want to play with.
Okay, although your program runs as wanted I digged a bit into the source code to find the source of this behaviour. So what I think is happening is that your second player controller is created as a spectating one half the time. For spectating controllers no pawn is spawned. To override this strange behaviour consistently, I would check "Spawn Players as Spectators" in your game mode details. Then, you can override the event OnPostLogin which should guarantee that you have a valid player controller. I came up with something like this:
This of course only works if you have enough player starts to iterate through ;) And I don't know the behaviour in multiplayer games, because creating players, controllers, spawning default pawns, etc. is bound to network code, so chances are this only executed on the server, but I really don't know.
And to create the second player, you can simply call "Create Player" after Begin Play (e.g. in your level blueprint).
Alternatively, you can override "Handle Starting New Player" in your game mode. This is the original implementation:
So you can override this in your blueprint and call "Restart Player" everytime instead. Should also work, but I havn't tried.
answered Apr 15 '17 at 02:38 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here