Actor Movement 'Physics' Replication

I have a custom class (esentially an item/pickup) extended from Actor, this class has two components (Sphere, StaticMesh).

BaseInteractionRange = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("BaseInteractionRange"));

RootComponent = BaseInteractionRange;

PickupMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PickupMesh"));
PickupMesh->SetMobility(EComponentMobility::Movable);
PickupMesh->SetSimulatePhysics(true);
PickupMesh->AttachTo(RootComponent);

Problem is when one client interacts with the object (punts it, moves it, kicks it) it replicates very sloppily and ends up being in completely different locations/rotations on different clients. Is there a way to handle this so all actors of this class and its subclasses are in same location/rotation on all clients?

Or is another completely different approach needed? (this objects may be placed in the world or spawned dynamically).

#Player-Controlled Replicating Physics Movement

I got physics replication working for even the hardest case, which is human-controlled movement of a physics simulating character

I dont know of any native UE4 support for this, so I went my own route.

I could discuss this further with you via pm on the forums

Rama

While reading through different answers on Answerhub I found that StaticMeshActor - with proper settings is former KActor.

This made me extend my custom class from StaticMeshActor and once I applied all the proper settings for Replication it fixed all problems I had with this and just generic settings

    bReplicates = true, 
    bReplicatesMovement = true
    StaticMeshComponent->SetMobility(EComponentMobility::Movable); 
    StaticMeshComponent->SetSimulatePhysics(true);

I could not do this with just Actor on its own, which makes me think there is something extra in there to make it replicate far more accurately. Thank you Rama for the answer you provided, it will come handy at a later point for me without a doubt when I will have to work with replication/movement of physics based SkeletalMeshes :slight_smile:

Hi, I had the same issue, and had problems to implement the Actor OnHit Event too. Even with a NetMulticast Replication, physics was not replicated properly (exactly what you said on kick, etc…).

So I search on the internet why this could happen, and I thing I have understand something, it is the way that movement is replicated through a multiplayer game. I think (I may wrong) physics is replicated in the same way than animation of character, the client send the hit to the server and, waiting for the response, it interpolate where the object should be. Then the client receive the response, make a correction of previous position and transform of the object (the interpolate one) , apply it, send a new hit event, etc…

So to properly do that, you have to implement all of this on your actor, and this would prevent objects going out of sync, I was a little disappointed to have to do all of that, so I have searched further more, make some test, and I found THE Solution, you should inherit from AStaticMeshActor, it is a base class which contain a staticmeshcomponent, exactly like what you are making, but the physics replication seems to be already implemented. (I have no more problem with the onhit event, and physics).
In your .h:

#pragma once

#include "Engine/StaticMeshActor.h"
#include "UsableActor.generated.h"

/**
 * 
 */
UCLASS()
class EARTHDEFENDER_API AUsableActor : public AStaticMeshActor
{
	GENERATED_BODY()

      (.......)

(To properly do that, you should create a new c++ class in UE Editor, I have tried to just change inheritance on visual studio, but the hot reload didn’t work)