hello i am using UE4.25.4 and trying to make a pickup based on StaticMeshActor . I’m trying networking. Below is my code
pickup.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Engine/StaticMeshActor.h"
#include "Pickup.generated.h"
/**
*
*/
UCLASS()
class BATTERYWARS_API APickup : public AStaticMeshActor
{
GENERATED_BODY()
public:
// set the default values
APickup();
// networking
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
// returns pickup state
UFUNCTION(BlueprintPure, Category = "Pickup")
bool IsActive();
// allow other class to change pickup state
UFUNCTION(BlueprintCallable, Category = "Pickup")
void SetActive(bool NewPickupState);
// pickup is active or not
protected:
UPROPERTY(ReplicatedUsing = OnRep_IsActive)
bool bIsActive;
// whenever bIsActive updated
UFUNCTION()
virtual void OnRep_IsActive();
};
pickup.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Pickup.h"
#include "Net/UnrealNetwork.h"
#include "GeneratedCodeHelpers.h"
APickup::APickup()
{
// tell engine to replicate this actor
bReplicates = true;
// pickups do not need tick every frame
PrimaryActorTick.bCanEverTick = false;
if(GetLocalRole() == ROLE_Authority)
{
bIsActive = true;
}
}
void APickup::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super()::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(APickup, bIsActive);
}
bool APickup::IsActive()
{
return bIsActive;
}
void APickup::SetActive(bool NewPickupState)
{
if(GetLocalRole() == ROLE_Authority)
{
bIsActive = NewPickupState;
}
}
void APickup::OnRep_IsActive()
{
}
Error : Pickup.cpp(25): [C2039] ‘GetLifetimeReplicatedProps’: is not a member of ‘`global namespace’'
Pickup.cpp(25): [C2146] syntax error: missing ‘;’ before identifier 'GetLifetimeReplicatedProps’