im a bit stuck on how to make a UObject replicate its variables from server to client, im very new to c++ and just started learning it after getting the hang onf the engine in genereal by using BP, what im trying to do now is basically have a weapon object (not using actors because it doesnt need a visual representation, as its the item that stores data about the weapon, such as ammo and reload animations) replicate how much ammo that weapon has to other clients, i have the UObject already set up to be replicated through other actors, now i need to know how to replicate variables from the UObject’s blueprint child class.
Any help would be greatly appreciated since i am stuck on this for quite a while now
UObject .h
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "WeaponObject.generated.h"
/**
*
*/
UCLASS(Blueprintable)
class SHOOTER_PROJECT_API UWeaponObject : public UObject
{
GENERATED_BODY()
public:
virtual bool IsSupportedForNetworking() const override { return true; };
void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>&OutLifetimeProps);
};
UObject .cpp
#include "WeaponObject.h"
#include "Net/UnrealNetwork.h"
void UWeaponObject::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps)
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
UBlueprintGeneratedClass* BPClass = Cast<UBlueprintGeneratedClass>(GetClass());
if (BPClass) BPClass->GetLifetimeBlueprintReplicationList(OutLifetimeProps);
}