Server RPC not updating Client property

If I have an actor that is set to replicated, and i use a server RPC to update a property on that actor,
Do i need to set the property to Replicated or ReplicatedUsing for it to reflect on the client? or are those used for showing other connected clients.

Only the client who sends the RPC needs to know about it (its an inventory item)

Currently have an RPC updating the inventory and its reflected on the server but its currently not updating the clients property (TArray) - its a component owned by an actor and its running the RPC fine. just not updating the client local property.

I have attmpted setting the property to replicated, replicatedUsing and also nothing at all.
It never reflects on the client.

SOLUTION From video, I was unaware that the replicate using could pass back the new value, I figured it would just auto sync.

.h

	UPROPERTY(ReplicatedUsing=OnRepInventoryUpdated)
	TArray<TObjectPtr<UALCItemBase>> InventoryContents;

	UFUNCTION()
	virtual void OnRepInventoryUpdated(TArray<UALCItemBase*> NewInventory);
.cpp


void UALCInventoryComponent::OnRepInventoryUpdated(TArray<UALCItemBase*> NewInventory)
{
	InventoryContents = NewInventory;
	for (UALCItemBase* const& InventoryItem : GetInventoryContents())
	{
		UE_LOG(LogTemp, Warning, TEXT("InventoryItem: %s"), *InventoryItem->TextData.Name.ToString());

		InventoryTotalWeight += InventoryItem->GetItemStackWeight();
	}

	OnInventoryUpdated.Broadcast();
}
1 Like

Thanks for the reply, Im watching it now and ill make it as a solution if it answers my question :slight_smile:

Part three of the series is also pretty informative.

1 Like

Fantastic, so my issue was that I was unaware that RepNotify could also pass the new value and I had to set it on the client.

another issue has arise, my Widget .Broadcast(); updater wont run on the RepNotify function :frowning:

void UALCInventoryComponent::OnRepInventoryUpdated(TArray<UALCItemBase*> NewInventory)
{
	InventoryContents = NewInventory;
	for (UALCItemBase* const& InventoryItem : GetInventoryContents())
	{
		UE_LOG(LogTemp, Warning, TEXT("InventoryItem: %s"), *InventoryItem->TextData.Name.ToString());

		InventoryTotalWeight += InventoryItem->GetItemStackWeight();
	}

	OnInventoryUpdated.Broadcast();
}

Ill have to figure out another solution. Thanks again

Have you bound the delegate inside of your inventory widget?

Put a breakpoint at OnInventoryUpdated.Broadcast(); and see if it is called.

Oh and one thing to know about onrepnotify => it’s only called on the clients.
If you have a listen server and want to update there then you need to call the function manually (best to put an authority check before to see if you are on the server first)

1 Like

Yeah its called but for some reason its empty on the RepNotify function

OnRepInventoryUpdated

If called from the Client before calling the RPC it works correctly (but runs before the inventory is updated)

The function that calls The server RPC

As for only running on the client that should be fine. its only meant for the client to know about (since the RPC should update the server version even if listen server)

You can set a parameter in the delegate of type TArray<UALCItemBase*> and pass it in the broadcast.
Though it shouldn’t be necessary.

Have the client update their own inventory ui once it’s repnotify is called (have it refresh inside of the onrepnotify function).