Ok, so, I’ve been fighting this one for a day or so now and I’ve got nothing.
I have an Actor Component for my Inventory, and inside of that I have 4 properties that are pointers to a weapon.
The Inventory spawns fine and replicates to clients, but the contents of that inventory do not. Everything I’ve seen so far in the documentation states that it should replicate, but I’m having no luck.
is the relevant part of my header. As you can see, all of the uproperties are marked Replicated.
#pragma once
#include "Object.h"
#include "Core.h"
#include "BaseEmpiresInventory.generated.h"
UCLASS()
class EMPIRES2_API UBaseEmpiresInventory : public UActorComponent
{
GENERATED_UCLASS_BODY()
public:
UPROPERTY(VisibleAnywhere, Category = General, Replicated, ReplicatedUsing=OnRep_Pistol)
class ABaseEmpiresWeapon* Pistol;
UPROPERTY(VisibleAnywhere, Category = General, Replicated, ReplicatedUsing = OnRep_Primary)
ABaseEmpiresWeapon* Primary;
UPROPERTY(VisibleAnywhere, Category = General, Replicated, ReplicatedUsing = OnRep_Tertiary)
ABaseEmpiresWeapon* Tertiary;
UPROPERTY(VisibleAnywhere, Category = General, Replicated, ReplicatedUsing = OnRep_Special)
ABaseEmpiresWeapon* Special;
UFUNCTION()
void OnRep_Pistol();
UFUNCTION()
void OnRep_Primary();
UFUNCTION()
void OnRep_Tertiary();
UFUNCTION()
void OnRep_Special();
///More functions
};
is the .cpp file
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);
}
///...
As you can see, The inventory items are set to be replicated.
I construct the character like this:
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, it should be replicating according to all of the documentation on the wiki and on the docs.
However, whenever I run my game, the client does not have the properties replicated to the client. All those pointers are NULL, and the OnRep functions aren’t being called.
Any ideas on what I’m doing wrong?