How To REPLICATE the Door code On MULTICAST and SERVER?

#pragma once

include “CoreMinimal.h”
include “GameFramework/Actor.h”
include “Components/StaticMeshComponent.h”
include “Components/TimelineComponent.h”
include “MyInterface.h”
include “MyDoor.generated.h”

class AMyCharacter;

UCLASS()
class INTHEFRONT_API AMyDoor : public AActor, public IMyInterface
{
GENERATED_BODY()

public:
// Sets default values for this actor’s properties
AMyDoor();

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

public:
// Called every frame
virtual void Tick(float DeltaTime) override;

virtual void OnInteractDoor();

void ToggleDoor();

UPROPERTY(VisibleDefaultsOnly, Category = "Mesh")
UStaticMeshComponent* DoorFrame;

UPROPERTY(VisibleDefaultsOnly, Category = "Mesh")
UStaticMeshComponent* Door;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Animation")
UCurveFloat* CurveFloat;

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Door")
bool IsDoorOpen = false;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Door")
float DoorRotateAngle = 90.f;

UPROPERTY()
AMyCharacter* MyCharacter;	

protected:
FTimeline Timeline;

bool DoorSameSide;

void OpenDoor(float Value);

void SetDoorOnSameSide();

};

include “MyDoor.h”
include “MyCharacter.h”

// Sets default values
AMyDoor::AMyDoor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;

DoorFrame = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("DoorFrame"));
DoorFrame->SetupAttachment(RootComponent);

Door = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Door"));
Door->SetupAttachment(DoorFrame);

}

// Called when the game starts or when spawned
void AMyDoor::BeginPlay()
{
Super::BeginPlay();

if (CurveFloat)
{
	FOnTimelineFloat TimelineProgress;
	TimelineProgress.BindUFunction(this, FName("OpenDoor"));
	Timeline.AddInterpFloat(CurveFloat, TimelineProgress);
}

if (IsDoorOpen)
{
	Timeline.Play();
}

}

// Called every frame
void AMyDoor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

Timeline.TickTimeline(DeltaTime);

}

void AMyDoor::OnInteractDoor()
{

ToggleDoor();
IsDoorOpen = !IsDoorOpen;

}

void AMyDoor::ToggleDoor()
{
if (IsDoorOpen)
{
Timeline.Reverse();
}
else
{
if (!Timeline.IsPlaying())
{
SetDoorOnSameSide();
Timeline.Play();
}
}
}

void AMyDoor::OpenDoor(float Value)
{
float Angle = DoorSameSide ? -DoorRotateAngle : DoorRotateAngle;
FRotator Rot = FRotator(0.f, Angle * Value, 0.f);
Door->SetRelativeRotation(Rot);
}

void AMyDoor::SetDoorOnSameSide()
{
if (MyCharacter)
{
FVector CharacterFV = MyCharacter->GetActorForwardVector();
FVector DoorFV = GetActorForwardVector();
DoorSameSide = (FVector::DotProduct(CharacterFV, DoorFV) >= 0);
}
}

How To REPLICATE the Door code On MULTICAST and SERVER???

Try set SetReplicateMovement(true); on door actor and replicate the Door static mesh. Also, make sure to create a RPC on server to play the timeline. Make sure to read: Multiplayer Network Compendium | An Unreal Engine Blog by Cedric Neukirchen

You only want to replicate the door state. Open or closed. Let each client handle the timeline process.

Rep_notify is your friend here.

Hey, the video is about blueprint code but i programming on c++ code

To replicate the door code on multicast and server, you can use the OnRep_IsDoorOpen function. This function is called on the server and all clients when the IsDoorOpen property is changed.

Here’s an example of how you can use OnRep_IsDoorOpen to replicate the door code:

void AMyDoor::OnRep_IsDoorOpen(bool NewValue)
{
    if (NewValue)
    {
        // Open the door on the server
        OpenDoor(1.0f);

        // Notify all clients that the door is open
        GetLifetimeReplicatedProps().BroadcastRep_IsDoorOpen(NewValue);
    }
    else
    {
        // Close the door on the server
        CloseDoor();

        // Notify all clients that the door is closed
        GetLifetimeReplicatedProps().BroadcastRep_IsDoorOpen(NewValue);
    }
}

In this example, the OnRep_IsDoorOpen function checks the new value of IsDoorOpen. If it’s true, it opens the door on the server and notifies all clients that the door is open. If it’s false, it closes the door on the server and notifies all clients that the door is closed.

Note that you’ll need to add the IsDoorOpen property to the list of replicated properties in the AMYDOOR_API macro in the MyDoor.h file:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/StaticMeshComponent.h"
#include "Components/TimelineComponent.h"
#include "MyInterface.h"
#include "MyDoor.generated.h"

class AMyCharacter;

UCLASS()
class INTHEFRONT_API AMyDoor : public AActor, public IMyInterface
{
    GENERATED_BODY()

public:
    // Sets default values for this actor’s properties
    AMyDoor();

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

    // Called every frame
    virtual void Tick(float DeltaTime) override;

    virtual void OnInteractDoor();

    void ToggleDoor();

    UPROPERTY(VisibleDefaultsOnly, Category = "Mesh")
    UStaticMeshComponent* DoorFrame;

    UPROPERTY(VisibleDefaultsOnly, Category = "Mesh")
    UStaticMeshComponent* Door;

    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Animation")
    UCurveFloat* CurveFloat;

    UPROPERTY()
    AMyCharacter* MyCharacter;      
    protected:
        FTimeline Timeline;

    bool DoorSameSide;

    void OpenDoor(float Value);

    void SetDoorOnSameSide();
};

#include "MyDoor.h"
#include "MyCharacter.h"

// Sets default values
AMYDOOR_API AMyDoor::AMYDOOR_API()
{
    // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
    PrimaryActorTick.bCanEverTick = true;

    DoorFrame = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("DoorFrame"));
    DoorFrame->SetupAttachment(RootComponent);

    Door = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Door"));
    Door->SetupAttachment(DoorFrame);
}

// Called when the game starts or when spawned
AMYDOOR_API void AMyDoor::BeginPlay()
{
    Super::BeginPlay();

    if (CurveFloat)
    {
        FOnTimelineFloat TimelineProgress;
        TimelineProgress.BindUFunction(this, FName("OpenDoor"));
        Timeline.AddInterpFloat(CurveFloat, TimelineProgress);
    }

    if (IsDoorOpen)
    {
        Timeline.Play();
    }
}

// Called every frame
AMYDOOR_API void AMyDoor::Tick(float DeltaTime)
{
hope it works!

Yup it certainly is. Translate to C++

DoorState (rep_notify)
OnRep DoorState function uses the doorstate’s value to determine whether to open or close.


Do not replicate movement. It uses too much bandwidth and looks like hot garbage on the client.