Server Side Replication. HOW


Edit:
To further this question from the information I have received from others I would probably like to preface saying I need to figure out a way to replicate a hovercraft or simply put a “Flying Pawn” in a multiplayer game (server side).
To be honest I never thought it would be so hard to just replicate basically a cubes position and rotation in an effective way.

Ok so i’m going mental please help. I have been working on trying to figure this out for the past week. I really just need someone to try and work with me to figure out the best way of getting this to replicate, because I simply can’t even get it to work. I’m pretty new to this.

I first mainly worked on getting a bounding box to randomly spawn pickups on both client and server (so the random location, and pickup itself is replicated for both). That works fine for the most part and as a result have somewhat of an idea of how replication works.

The pawns logic is all within the pawn itself as I developed the mechanics before working on multiplayer. So I tried to replicate the events to the server, which is not only a bad way of doing it because its client side mirroring it to the server, but it also just didn’t work. (Nothing seemed to update the location on the server)

So to the actual question, I finally said ■■■■ it and was going to put the logic on the server and basically use the pawn itself as the input that way everything is calculated on the server and the client is just the keyboard if you will, as it should be for good networking. So I read somewhere that PlayerStates are calculated on the server and spend about a day and a half putting the logic in a PlayerState and remapping allll of the targets to the new casting I had to do referencing the pawn.
After it finally looks setup nothing replicates or really even works at all.
I have come to the conclusion i’m doing it all wrong and i’m at a brick wall and need to be pointed in the right direction.

WHERE SHOULD MY PLAYER MOVEMENT LOGIC GO!
Why is it impossible for me to find how to store movement server side, and the pawn references it. Clearly its not playerstate unless I can somehow actually save the work i’ve done and its somehow right. I know HOW server side networking works, I need to know where the appropriate place for my pawn logic so its stored on the server, and what should be stored on the player and what should be stored on the server (which is where exactly?)?

are you using a character or a more basic kind of Pawn? I ask because Character does a lot of things for you like telling the server about the Movement Input and smoothing out network movements. All other Pawn classes do not do that.

Playerstates are for storing everything you want to replicate about the player that isnt related to movement (you can store it there too but i dont see the point. Actors already have location and rotation variables on them and the Pawn is an actor, so just use a Server RPC to have the client move its pawn on the server and Rellucate Movement updates it to everyone else. BUT it’s choppy unless you use Character instead of regular pawn, and if you do That, you dont need RPCs for movement as it automatically tells the server to move its version of the same pawn and MUCH smoother)

You can first look in the ACharacter reference to obtain an overview of what it holds. It has quite a lot of methods as you might expect.

In the ACharacter there is a UCharacterMovementComponent. This is where all movement logic goes along with the server position correction. You can get the code from GitHub.com: Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent .cpp and .h and check how the networking is realized. (Note that the cpp file is over 10000 lines but it is quite well commented)

I can suggest you make your own component matching the UCharacterMovementComponent interface and put all your movement logic + networking there.

Edit:

I assumed that you NEED a custom movement component but please check the ACharacter as it might provide all the functionality that you need.

This is very helpful, I couldn’t find anywhere that just says the direct thing I should be using and what the player state is actually best for, most just say oh its for heath variables etc. Couple of questions however. When one says run “on” the server, that simply means run events in the character blueprint replicated on the server?
I am using a pawn, unreal suggests the character is for vertical “Walking” characters. Mine is actually neither its kind of a hovercraft. The mechanics are in the pawn class the actual mesh itself is currently a glorified rectangle as most vehicles are. If I could still use the character class let me know, it could take many hours to set it up so id rather know if i’m on the right track first.
Are there specific classes for vehicles that would work well for floating vehicles?
I’m probably going to restart my project in order to do it with replication in mind instead of trying to implement multiplayer after mechanics are already set in place,
but I still want to make sure I have an understanding of this before I do so or i’ll be in the same boat.

I’m guna be honest, your answer kinda scares me. I haven’t really worked at all with C++ in unreal just surface visual scripting it seemed to provide me with everything I needed up to now. It would mean the world to me if you could baby step me to some sort of solution, I love the game I have developed so far and would hate for it to die just because I can’t figure out how to ■■■■■■■ replicate it effectively.

Effective Network Replication is not as trivial as it initially seems. It is one of the hardest problems in game development and there are many specific optimizations entirely dependent on your project.

I will not be able to “baby step” you through the implementation of a Movement Component with network correction as I can’t really claim that I know it that well. I just know the overall logic.

I strongly suggest you go with a Character as @mightyenigma implied. CharacterMovementComponent contains quite a lot of movement behaviors - flying, walking, swimming and you can even make custom movement behavior.

You can make it work with the hovercraft idea, I’m sure. Here is a Live Training Unreal video on how they make a tank out of a character. (not sure how similar but it might help)

As for the PlayerState object - It is the only thing that is transferred between levels/sessions for each player. You can change the player controller, the pawn but the PlayerState will remain the same. This makes it very useful to transfer information like chosen character class from the main menu to the level or in multiplayer - the team, name and avatar from the lobby menu to the multiplayer match. Sometimes it is used to store inventory items to transfer between different levels.

Also remember GameInstance persists between levels and sessions but does NOT replicate across network, so it is good for keeping track of settings and such locally but not remotely. Thank you for the link about Character tank. I have spent about 2 or 3 months trying to get a Tanklike pawn to replicate smoothly. Wish I had known about that video before. I finally had settled on making my tank very round and accounting for the capsule by saying it is a hover tank.

-UPDATE: I watched the video and he doesn’t actually use Character, just basic Pawn. oh well.

…accounting for the capsule by saying it is a hover tank.

Nicely played! :wink:

I find the official Unreal documentation on Networking quite lacking. Not that it is not thorough it’s just that there are bits here and there and it’s hard to grasp the overall picture.

I find this PDF by Cedric Neukirchen much more useful and informative.

I hope it helps.