I’m having this problem in my main project, but I’ve also reproduced it in a more minimal tutorial project I was messing around with a while ago. Here are the relevant bits of code:
Header file:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Target.generated.h"
UCLASS()
class TESTREUBENTARGETGAME_API ATarget : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ATarget();
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
UFUNCTION()
void OnRep_Repped();
UPROPERTY(Transient, ReplicatedUsing = OnRep_Repped)
float Repped;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
CPP file:
#include "Kismet/GameplayStatics.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Net/UnrealNetwork.h"
#include "Target.h"
#include "Math/UnrealMathUtility.h"
// Sets default values
ATarget::ATarget()
{
// 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;
bReplicates = true;
}
void ATarget::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(ATarget, Repped);
}
void ATarget::OnRep_Repped()
{
UE_LOG(LogTemp, Warning, TEXT("OnRep_Repped Called"));
}
// Called when the game starts or when spawned
void ATarget::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ATarget::Tick(float DeltaTime)
{
UE_LOG(LogTemp, Warning, TEXT("Setting random"));
Repped = FMath::RandRange(0.0f, 100.0f);
}
Every example I’ve found online, for instance, the network compendium, leads me to believe this is all I need. Yet, I see the “Setting random” log line, but not the “OnRep_Repped Called” log line. I’ve observed the actual value of the replicated field being replicated in my other project, but no matter how I mess around, I can’t get the OnRep function to be called.