Property not getting replicated C++

I have an actor component that is called Inventory.h that has a variable TArray inventory; that is not getting replicated.

Here’s my GetLifetimeReplicatedProps at Inventory.cpp

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

	// Replicate to everyone
	DOREPLIFETIME(UInventory, inventory);
	DOREPLIFETIME(UInventory, equippedItems);
	DOREPLIFETIME(UInventory, weaponsInInv);
	DOREPLIFETIME(UInventory, equippedItemSelected);

}

When I change the variable inventory ON THE SERVER the client doesn’t get the modifications. I don’t know if I did something wrong or if I need to create a RPC call from the server to the owning client to send the variable value.

Thanks in advance!

I am going to guess that since your object UInventory starts with a U that you are inheriting from a UObject. If so, there is your problem. According to the UE4 docs, Actors replicate, but UObjects do not:

If you are using an Actor and not a UObject and it still does not work, make sure you are also properly marking the individual properties that you want to replicate with:

UPROPERTY(Replicated)

And of course make sure that you set bReplicates = true; in your constructor.

I missed the part where you said your UObject was an actor component.

Did you add this to your actor component?

virtual bool IsSupportedForNetworking() const override
    {
        return true;
    }

See this section for more code you have to add to get subobjects to replicate:

Yep, I was just about to say that exact thing. That error gets me all the time :slight_smile:

Thank you so much. I THINK my problem is solved… The only problem now is that I get these errors when compiling:

CompilerResultsLog:Error: Error C:\Users\lucas\GAME\ShooterGame\Source\ShooterGame\ShooterGameCharacter.cpp(84) : error C2275: 'AShooterGameCharacter': illegal use of this type as an expression
CompilerResultsLog:Error: Error C:\Users\lucas\GAME\ShooterGame\Source\ShooterGame\ShooterGameCharacter.cpp(84) : error C3861: 'DOREPLIFETIME': identifier not found

The errors are in my character class (which has the UInventory component) and refers to

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

    //I guess I can't use AShooterGameCharacter as a type here...
	DOREPLIFETIME(AShooterGameCharacter, inventoryActor);
}

Whoops sorry, solved it haha. I used
#include “Networking.h”

instead of
#include “UnrealNetwork.h”

Did this solve the problem?