Alright, this one is an oddball.
I have a Component for my Character for inventory items. It looks like this:
UBaseEmpiresInventory.h:
#pragma once
#include "Object.h"
#include "Core.h"
#include "BaseEmpiresInventory.generated.h"
UENUM(BlueprintType)
namespace EInfantryInventorySlots
{
enum Type
{
Slot_Sidearm = 0,
Slot_Primary = 1,
Slot_Tertiary = 2,
Slot_Ability = 3,
Slot_Skill1 = 4,
Slot_Skill2 = 5,
Slot_Skill3 = 6,
Slot_Skill4 = 7,
Slot_Count = 8,
Slot_None = 9,
};
}
/**
*
*/
UCLASS()
class EMPIRES2_API UBaseEmpiresInventory : public UActorComponent
{
GENERATED_UCLASS_BODY()
public:
UPROPERTY(VisibleAnywhere, Category = General, ReplicatedUsing=OnRep_Pistol)
class ABaseEmpiresWeapon* Pistol;
UPROPERTY(VisibleAnywhere, Category = General, ReplicatedUsing = OnRep_Primary)
ABaseEmpiresWeapon* Primary;
UPROPERTY(VisibleAnywhere, Category = General, ReplicatedUsing = OnRep_Tertiary)
ABaseEmpiresWeapon* Tertiary;
UPROPERTY(VisibleAnywhere, Category = General, ReplicatedUsing = OnRep_Special)
ABaseEmpiresWeapon* Special;
UFUNCTION()
void OnRep_Pistol();
UFUNCTION()
void OnRep_Primary();
UFUNCTION()
void OnRep_Tertiary();
UFUNCTION()
void OnRep_Special();
virtual void ClearInventory();
virtual void AddItem(EInfantryInventorySlots::Type Slot, ABaseEmpiresWeapon* Item);
virtual ABaseEmpiresWeapon* GetItemInSlot(EInfantryInventorySlots::Type Slot);
virtual int32 GetInventorySize()
{
return EInfantryInventorySlots::Slot_Count;
}
};
UBaseEmpiresInventory.cpp
#include “Empires2.h”
#include “BaseEmpiresInventory.h”
#include “UnrealNetwork.h”
#include “BaseEmpiresWeapon.h”
UBaseEmpiresInventory::UBaseEmpiresInventory(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
void UBaseEmpiresInventory::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(UBaseEmpiresInventory, Pistol);
DOREPLIFETIME(UBaseEmpiresInventory, Primary);
DOREPLIFETIME(UBaseEmpiresInventory, Tertiary);
DOREPLIFETIME(UBaseEmpiresInventory, Special);
}
///Snip
void UBaseEmpiresInventory::OnRep_Pistol()
{
TRACE("Pistol Replicated: %u", Pistol);
}
void UBaseEmpiresInventory::OnRep_Primary()
{
TRACE("Primary Replicated: %u", Primary);
}
void UBaseEmpiresInventory::OnRep_Tertiary()
{
}
void UBaseEmpiresInventory::OnRep_Special()
{
}
It’s constructed in my Character here:
AEmpires2Character::AEmpires2Character(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
///.... Snipped extra code that isn't relevant
Inventory = PCIP.CreateDefaultSubobject<UBaseEmpiresInventory>(this, TEXT("Inventory"));
Inventory->SetNetAddressable();
Inventory->SetIsReplicated(true);
this->bAlwaysRelevant = true;
}
So, the problem is that the Pistol and Primary weapon properties aren’t being replicated to the client.
Am I missing anything? I’ve followed all of the documentation to replicate this component, but not dice on getting it to actually replicate. The OnRep functions are not being called and when I step through in a debugger the properties are NULL.