Download

'SetReplicates': identifier not found

I get this error on compile:

C3861 ‘SetReplicates’: identifier not found

I’m setting up an Actor Component called FuelComponent (each player has a Fuel value that can go up/down). I want everyone to know what other players’ Fuel value is. Any ideas?

.h


#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "FuelComponent.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class TF2020_API UFuelComponent : public UActorComponent
{
    GENERATED_BODY()

public:    
    // Sets default values for this component's properties
    UFuelComponent();

    void IncreaseFuel();
    void DecreaseFuel();
    int GetFuel();

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

    UPROPERTY(Replicated, BlueprintReadOnly, Category = "FuelComponent")
    int Fuel;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FuelComponent")
    int DefaultFuel = 2;

};

.cpp


#include "FuelComponent.h"
#include "Net/UnrealNetwork.h"

// Sets default values for this component's properties
UFuelComponent::UFuelComponent()
{
    // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
    // off to improve performance if you don't need them.
    PrimaryComponentTick.bCanEverTick = true;

**    SetReplicates(true);**

}

void UFuelComponent::IncreaseFuel()
{
    Fuel++;
}

void UFuelComponent::DecreaseFuel()
{
    Fuel--;
}

int UFuelComponent::GetFuel()
{
    return Fuel;
}

// Called when the game starts
void UFuelComponent::BeginPlay()
{
    Super::BeginPlay();

    Fuel = DefaultFuel;

}

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

    DOREPLIFETIME(UFuelComponent, Fuel); // Will replicate this variable to the client
}

In components its SetIsReplicated, and in new UE versions, its SetIsReplicatedByDefault for constructor (or something similar)