Multiplayer replication and other issues

Hi! I am trying to digest and undestand how multiplayer works but I was struggling for days and still cant get it even watching videos on YT, etc.

I did this test: two Pawn cubes that are controlled with mouse and keyboard.
there is a boolean inside that changes the control type from physics control (the cube is moved by forces) and non physics (just adding rotation and location offset to the cube).

I added 2 player start in the scene as defaul pawn my pawn class

one problem is this:

sometimes the client just dont spawn…idk why…just black screen.

I am running PIE windows, 2 players and as listener server

image

so first problem is erratic black screen on client only player and must retry playing.
also in client window, both players are in random places and not where player start
actors are placed. Floor is cosmetic (no collisions)

using physics control or non physics causes same problems.
client transforms are not being updated in the server side.

here is the project in case someone wants to see if can help.
Its UE 5.2

also a YT video showing all issues and setup:

Thanks in advance! :slight_smile:

Hey @eldany.uy

have a look at this project:

MultiplayerReplication.zip (101.3 KB)

hey @L1z4rD89 Thanks a lot for your simple and clear example!
In this example is very clear how to move the cubes on both cases
client and server in sync.

My project is a bit more complicated because I want to move player by applying physics (by adding force and torque).

I achieved a good sync by adding the control forces from the server ( all players
will replicate what server moves) but in server side things jitter ( its understandable).
for tackiling that last issue, I duplicated the visuals (meshes) and I just show actual visuals
on the server player (because there is not jitter) and in the clients I am showing the duplicated meshes that dont have physics because are just visuals and update transforms with Interp. Works like a charm.

The final step to make it all work is transfer input controls from the clients to the server
so server can manage the forces for all of them but I am having HUGE problems
trying to figure out hot to transfer a simple Vector2D variable from each player to the
server so Server can appy the forces to move.

This is what I am trying right now and is not working:

my actor has an enhanced input and tries to send the Vector2D movement of the left thumbstick to the server. The player sends its playerID and thumb Value

Players have an instance of Gamestate stored in gamestate variable so I dont have to cast it every time…inside the game instance I have an Array with players data. Its a truct that only holds the Vector 2D for now like this:

As I have 10 players, I already created 10 items in the gamestate ‘player data’ array and each player registers there when game begins so this array has the ten players and matches ID with array index.

so this is on beginplay of the Actors:

now I just want the read the values of all imputs in gamestate:

I only receive a value when I move the SERVER side Actor.
When I move a client joystick there is not data displayed in gamestat :frowning:

Any suggestions?
I dont want to mark this as solved even you solved a lot of clarity with your example but I am afraid if I mark as solved I wont get more replies :slight_smile:

to make the long explanation shorter I jast want to transfer a value (vector2D) from a client to the server and print the value from server side.

I dont get why something so simple like this just dont work
(JUST WORKS FOR SERVER PLAYER)

my Actor is replicated:

my variable to send is replicated:

I run this in level blueprint:

al default values (0,0) at least I test in the server window.

Its driving me really crazy.

here is the test problem in a video

even this only works if tested on server window but not in client window

I am feeling so dumb now… :frowning:

Hey @eldany.uy

So, replication (a variable with replication enabled) works from Server to Client. To send a value from client to server you need an RPC.

like this? doesnt works

how’d you do this?

press S in a client and print ‘hello’ in the server window.

Hey @eldany.uy

when you do it like that you should see that the server sends this message even when the client presses S (every window shows the message).

yes but is not working.

here I check if is owning client (actually it is because it accepts S input)
but is not working…client prints the owner name on both screens and thats it.

no hello print from server.

Hey @eldany.uy

I don’t know why this is happening and I don’t know what you changed in the project. Did you restart the editor? Did you try this in a new project?

I tried from a new project and same results…anyway I am using unreal 5.2.1 and found various bugs before…maybe I should try in other versions or maybe this is not the solution I am looking for.

I will mark this as solved because you shared the project that clearly shows how to replicate inputs in between clients, but the core that is make communication client–>server is not solved :frowning:

Hey @eldany.uy

What happens if you test this?
SendToServer.zip (21.9 KB)

I found the solution. PRoblem is that the actor is not the Client owner…the real client owner is the PLAYER CONTROLLER of that actor so the call from server must be done from Player controller and not the actual actor :slight_smile:

Anyway I really appreciate you took your time for help me out!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.