Download

How do I synchronize physics between Client and Server

How do I synchronize any physics between clients and the server all in blueprints? I want to know how to synchronize cloth physics, skeletal mesh physics, destruction physics and static mesh physics? Thank you if you are able to help! :slight_smile:
Sorry for double post, first one didn’t work properly.

This is difficult to achieve, i dont think its possible or feasible to do this in Blueprints. Someone maybe able to correct me on this but syncing the Physics Engine across a network is very resource intensive, this is the main reason why Physics is usually run locally.

Like DevilsD said, you don’t do it this way. It would be way too much data to transmit and a package loss would create a lot of problems with physics in general. What you might be able to do is trying to get certain physics outcomes for all of the clients by taking away control from the physics itself (aka have variables influencing the physics to reach a similar outcome on each client).

Static meshes are the only ones that you should/“can” sync, and the way to do it is creating a Static Mesh Blueprint and checking the Replicates option.

Forget about the rest, it’s too much data. Let the clients calculate cloth and ragdolls but just the visual aspect of it.

For example, let’s say that an event X happens and one character goes ragdoll, you could use Rep Notify to save “bandwidth”, but you have to make sure that the only collision transmited is the one from the character, a capsule collision component or whatever. And then make the clients calculate how gravity and surfaces affect the skeletal mesh.

In other words, you don’t sync certain physics when you can fake it.

The same with destruction physics, unless the only things you want to sync are visual events happening you can’t sync them on the network, it’s like trying to replicate all the particle data from an explosion.

Goat Simulator was made in UE3 and doesn’t have multiplayer for this reason.

As the others mentioned, in general you handle physics event locally and make it so they have no influence over gameplay (IE a chunk of a destructible might react to a projectile hitting it but it would not block that projectile since the chunk would be in a different position on other machines).

You can also write your own physic system and make it so there is no random and therefore every machine would see the same results out of a physic interaction.

HI

i have same problem , i 'm currently working on a MP project i like to make a simple bottle on the ground with enabled physics that interact (can be kicked ) by server (player 1) or the client (player 2) , problem is when it get kicked by player 1 or 2nd player the bottle move to other location but the collision stay in the other player location as blocked collision and make problem which the 2nd player can’t kick it and just collide with the collision . so its impossible to make such thing ? is there are a way to let the server only make the physics math and send it to the client but the client send the the info to the server when he touch the bottle so we see a physical object ? as just sending the location to the client will not be enough without client sending the info on how and where did he touch the object collision .

BR
MH

As I said, to replicate an object it must a Static Mesh Blueprint, then you can select the appropriate networking options. It usually is as simple as checking Replicates, Replicate Movement and Always Relevant if you need high priority replication.

Read this and play with it until you find a solution it satisfies you: https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/Networking/ReplicateActor/Blueprints/

I found this text too: https://udn.epicgames.com/Three/NetworkingOverview.html

This is too heavy to replicate…
The engine would have to be built around this feature for it to be somewhat performant, you can do it with RPCs, but that will cause massive lag hiccups on high latency.

Thanks masterneme

Then how do they do the grenade in multiplayer game on gears of war or any other MP game? i like to make a physical object to be enabled physics only on the server then replicate the movement to the client but the problem i face is that the collision of that physical object is not getting replicated and stay a as blocking volume on the client side without moving even the object move as peer the replication movement information . hope someone find a way on how to make a fake physical object for MP .

You can let physics run the phyx grenade on server then every X frame record its position and send it to the Client…
On Client, disable phyx body and VInterpTo grenade position to follow the path created by the physics engine on Server. Doesn’t need to be 100% accurate replication.

thanks for the suggestion , i was able to make it work with get from server and set world transform to client (i used sphere which roll ) here is below snaps .

spawn the object on server by player

cda208792fb1582b27ddd5f6202e2416651f2eac.jpeg

properties on the sphere actor blueprint
261d907c352ec03f9dfa201a653e4128743fde4c.jpeg

properties on the sphere actor blueprint / rep notify
dff4ca2442ec94da761ffdcddcb9cb491680f2b6.jpeg

but this will give problem if the speed of the object is fast like projectile so can you tell me pls how can i make it work with V or Tinterp ? as i couldn’t and i get wired result as i think i am getting it wrong , here is how i did it :

095d3e81fd6a616c2de9fcaea9aae546d5fa5d0b.jpeg

InterpTo would only be needed if you want to ignore an amount of frames and generate a “timeline” with key transform locations along X frames;
Updating it every frame on Client like that, InterpTo wouldn’t work, but that also means you are replicating it every frame. Lag may cause issues, but under a perfect connection it works just fine.

yeah i got what you mean seems simple sphere with my method take about 2kb from the bandwidth which is a lot but with adding delay 0.2 and interp it take a lot less but the interp is not smooth no matter what i put in interp speed . anyway thanks a lot for all the info you shared here .

This is one of the bigger weaknesses of Unreal Engine.
It uses a physics engine that is not guaranteed deterministic.
Additionally, the way it steps physics by frame time, means that you won’t even get the exact same step sizes on all clients (or server.)
Thus, you cannot keep physics 100% in sync.
By contrast, a deterministic physics engine with fixed step size would achieve this without too much network bandwidth use.

If you turn off simulation on client objects, and just let them use replication from the server, it will be reasonably accurate across clients.
There are two draw-backs:

  1. The response time for actions will be longer, because it requires a server round-trip.
  2. It uses more network bandwidth.

A grenade shouldn’t be this complicated, I had a project with the First Person Template and Cubes affected by physics and everything replicated just fine.

I mean the First Person Template’s projectile acts like a grenade and it doesn’t need any additional modifications, I used it to hit pyramids made of cubes and everything worked out of the box just checking Replicated and so on.

If I were you I would check the collision channels maybe you have something conflicting there, be sure to disable all collision from the static mesh and let the collision volume handle all the calculations.

If in doubt create a new project with the First Person Template and copy what it’s done there.

Once, I had all the collisions enabled and they did weird things.

Here is the Introduction to Blueprint Networking tutorial, he uses the Third Person Template and makes some physics affected replicated bombs.

Just finished the tutorial a min ago :slight_smile: you mentioned in the link for the 2nd time as i watched them all once before so i prepare myself for the new 24 ep MP series that released few days ago by epic team , as for grenade it was just an example and i think it have a physic behavior in gears of war mp game ,and the tutorial you are referring is not physic simulated only he add projectile movement with bounce to it as if it had physic simulated then he will get problem between the server and the client eventually when the grenade collide with the client ,

But anyway i like to know one thing from an expert of UE team :
If i make a new actor and i add to this actor a static mesh sphere and a collision attached to it as parent , when i enable replicate movement does that mean only the location of the sphere will be replicated to the client or both ? as to save the bandwidth the client doesn’t need to know the collision location fro the server as its already attached to the static mesh sphere which the location transferred to the client .

thanks again .

That’s the thing, with that setup the grenade IS affected by physics and it will react to collision and movement properly without the need of extra programming and it will be 100% replicated.

I had a project with movable cubes and grenades and they all reacted right and “physically correct”. I don’t know if I understand exactly what you want to achieve.

I get what you mean , my first post was about something else about other physical objects replication but i gave grenade as an example , as for grenade as you said the tutorials method works perfect .

If you are talking about the bottle change how its components are set up to match what you did with the grenade. If you have trouble with the collisions disable the mesh collisions and attach a cube as the base and a capsule as the body.

Everything must be inside a Static Mesh Blueprint and the component to be replicated is whatever you put as the Scene Root, now writing this I think that this may be what caused you troubles, can you paste a screenshot of your actor components?