I have a problem with my character movement when i’m spawning and possessing the character on Clientside manually. With manually I mean, when I press the Start game button (see video)
This Jittery movement does not occur when im either starting the game as Server OR when I set the pawn as default pawn in my gamemode. Then it works on both Server and Client, but this is not what I want, as i want the players to be able to choose what character they want to play.
I have been trying to get this to work for 3 days now and I cant seem to figure out what this is causing. I have read a lot of tips but none of them really worked. What i’ve tried so far is:
- Checking if the server and client share the same movement speed
- Checking if the pawn is possessed only once
- Checking if the movement is replicated properly
The GM needs to handle Spawning characters and the possession of them. This is the proper place, regardless the ability to do it elsewhere.
The way I handle this is to have a basic character set as the GM’s Default Pawn. The GM will spawn this character as soon as you connect to the server.
The GM only exists on the server in a packaged product. This means any communication between you and the GM has to go through the Controller class.
Set a Game Mode reference in the controller class via the GM’s OnPostLogin Event. This will only set it on the Servers copy of the controller.
From here you need an event in the Controller class (Run on Server, Reliable). And an event in the Game Mode to handle swapping the default out with the new choice character.
Call the controller event once selection is done. Pass any arguments/params to the GM event as needed. My reccomendation here is to use a struct that only contains simple types (int, string, name, enum, bool). No references to Objects or Classes.
It’s better to pass a name type for a data table look up vs fully referencing a class/obj.
The GM’s event will call a function to handle the work.
2 Likes
@Rev0verDrive Thanks for the detailed explanation! Although this seems to be working well, my goal is to have the game start without a pawn. The pawn should be spawned in through the game mode after the player has pressed start game.
If I’m correct, your method immediately spawns a character on level start through the GM.
This does work for me as well without jittery movement on the client-side. What doesn’t work properly is when the client possesses a character manually.
1 Like
The GM auto spawns a character immediately on client join. If you don’t want that behavior you have to overwrite it.
It depends right @Rev0verDrive, because I can set the default pawn to None, which would implicate that the GM will not spawn a default pawn.
This is desired behaviour. So I manage my spawns through the GM custom ‘SpawnCharacter’ event that gets called through the owning PC when necessary. The problem is that some values seem to not be properly replicated, hence the jittering/snapping movement.
I am wondering what this could be as this problem does not occur when the GM spawns the character through the ‘default pawn’ option.
I finally found the solution (dumb me). I have a property in my character base class named ‘initial walk speed’ which would be set when the character is spawned. This value was equal server-client. The problem was that this property would set the max walk speed on spawn which was NOT properly replicated, thus resulting in a movement speed difference between server and client.
Thanks for your detailed explanation, this surely did help a lot with ruling out probabilities! @Rev0verDrive