Property replication when archetype value differs from serialized value

Hello,

We’re having an issue and we’re not sure if it’s a bug or intended.

If you have a with a serialized with a value differing from it’s archetype’s value, if the server sets the value back to the archetype’s default value the property will not be replicated to clients.

From our investigation, this is due to the fact that the archetype’s default value is used to compare with the current value – since the current value matches the archetype’s default value, the property is not replicated, even if it differs from the actor instance’s serialized value.

Here is a small actor which reproduces the issue (it just takes an instance of this actor placed in a level with a TestValue set to something other than the default value of 100):

#pragma once
#include "CoreMinimal.h"
#include "TestActor.generated.h"

UCLASS()
class ATestActor : public AActor
{
	GENERATED_UCLASS_BODY()

public:
	virtual void BeginPlay() override;

	UPROPERTY(EditAnywhere, ReplicatedUsing = OnRep_TestValue)
	float TestValue = 100.f;

	UFUNCTION()
	void OnRep_TestValue();
};
  • #include “GAME.h”
    #include “TestActor.h”

    #include “Net/UnrealNetwork.h”

    ATestActor::ATestActor(const FObjectInitializer& ObjectInitializer)
    : Super(ObjectInitializer)
    {
    bReplicates = true;
    }

    void ATestActor::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
    {
    Super::GetLifetimeReplicatedProps(OutLifetimeProps);

      DOREPLIFETIME(ATestActor, TestValue);
    

    }

    void ATestActor::BeginPlay()
    {
    Super::BeginPlay();

      if (HasAuthority())
      {
      	TestValue = 100.f;
    
      	// This will never make it to the client, 
      	// as the network shadow state used to check if the value 
      	// has changed uses the archetype's value, which is the same.
    
      	// This makes it so the client never knows the value 
      	// changed from the serialized value loaded from data.
      }
    

    }

    void ATestActor::OnRep_TestValue()
    {
    // This never gets called as the value is never replicated.
    }

Is this intended? Are we doing something wrong?

Thank you,
Sebastien

Hello,

We’ve recently made a switch to a new bug reporting method using a more structured form. Please visit the link below for more details and report the issue using the new Bug Submission Form. Feel free to continue to use this thread for community discussion around the issue.

https://epicsupport.force.com/unrealengine/s/

Thanks