# TMap not working on client in online/replication

**URL:** <https://forums.unrealengine.com/t/tmap-not-working-on-client-in-online-replication/2361157>\
**Category:** Multiplayer & Networking\
**Tags:** Replication, online, tmap, unreal-engine, CPP, question\
**Created:** [February 26, 2025, 10:59pm UTC](https://forums.unrealengine.com/t/tmap-not-working-on-client-in-online-replication/2361157 "2025-02-26T22:59:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chevidal451](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chevidal451](https://forums.unrealengine.com/u/Chevidal451)\
**Post date:** [February 26, 2025, 10:59pm UTC](https://forums.unrealengine.com/t/tmap-not-working-on-client-in-online-replication/2361157/1 "2025-02-26T22:59:49Z")

</div>

Recently I saw that TMap was not replicated for Unreal, but if I dont want to replicate it, I just want to make calculations with the TMap structure and then if I want to replicate I will move the data to a particular structure. But I got problems doing the GetKeys() of my map, it says 0 but its 60, so I dont know what to do because when I try in standalone I get the right num.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Rev0verDrive](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rev0verdrive/32/907214_2.png) [@Rev0verDrive](https://forums.unrealengine.com/u/Rev0verDrive)\
**Post date:** [February 26, 2025, 11:17pm UTC](https://forums.unrealengine.com/t/tmap-not-working-on-client-in-online-replication/2361157/2 "2025-02-26T23:17:34Z")

</div>

need to see your code.

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [February 26, 2025, 11:31pm UTC](https://forums.unrealengine.com/t/tmap-not-working-on-client-in-online-replication/2361157/3 "2025-02-26T23:31:41Z")

</div>

> [@Chevidal451](#):
>
> , it says 0 but its 60

Are you talking about size?

```
TArray<int> Keys;
MyMap.GetKeys(Keys);

if (Keys.Num()==0) return;

```

Or are you talking about values?

`Keys[i] = 60`

> [@Chevidal451](#):
>
> when I try in standalone I get the right num

It should be the same everywhere

---

<div class="post-metadata">

**Author:** ![Rev0verDrive](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rev0verdrive/32/907214_2.png) [@Rev0verDrive](https://forums.unrealengine.com/u/Rev0verDrive)\
**Post date:** [February 26, 2025, 11:51pm UTC](https://forums.unrealengine.com/t/tmap-not-working-on-client-in-online-replication/2361157/4 "2025-02-26T23:51:38Z")

</div>

> [@Ivan3z](#):
>
> It should be the same everywhere

Depends on how and where you are adding to the TArray. Replication is only Server → Client.

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [February 26, 2025, 11:57pm UTC](https://forums.unrealengine.com/t/tmap-not-working-on-client-in-online-replication/2361157/5 "2025-02-26T23:57:27Z")

</div>

Yes you’re right.

I was also too brief. I meant in Editor and Standalone.

---

<div class="post-metadata">

**Author:** ![Chevidal451](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chevidal451](https://forums.unrealengine.com/u/Chevidal451)\
**Post date:** [February 27, 2025, 9:34am UTC](https://forums.unrealengine.com/t/tmap-not-working-on-client-in-online-replication/2361157/6 "2025-02-27T09:34:57Z")

</div>

basically I have an inventory state Tmap of FVectro2D and bool in Lyra, here the length is 60

```auto
void ULyraInventoryManagerComponent::DefaultInventoryState()
{
	float GridX = 0.f;
	float GridY = 0.f;
	
	for (int i = 0; i < InventorySize; i++)
	{
		InventoryState.Add(FVector2D(GridX, GridY), false);
		
		if(GridX == InventoryWidth-1)
		{
			GridX = 0.f;
			GridY++;
		}
		else
		{
			GridX++;
		}
	}

	TArray<FVector2D> ItemLocations;
	InventoryState.GetKeys(ItemLocations);

	// LENGTH == 60
	GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf(TEXT("LENGTH %d"), ItemLocations.Num()));
}

```

when I add an item the InventoryState says that its empty

````auto
ULyraInventoryItemInstance* ULyraInventoryManagerComponent::AddItemDefinition(TSubclassOf<ULyraInventoryItemDefinition> ItemDef, int32 StackCount)
{
	ULyraInventoryItemInstance* Result = nullptr;
	if (ItemDef != nullptr)
	{
		Result = InventoryList.AddEntry(ItemDef, StackCount);

		const UEO_InventoryFragment_Icon* Fragment = Cast<UEO_InventoryFragment_Icon>(Result->FindFragmentByClass(UEO_InventoryFragment_Icon::StaticClass()));

		if (Fragment)
		{
			bool bSuccess = false;
			int32 Remaining = StackCount;

			TArray<FVector2D> ItemLocations;
			InventoryState.GetKeys(ItemLocations);

			// length == 0
			GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf(TEXT("LENGTH in AddItemDefinition %i"), ItemLocations.Num()));
				
			AddItemFromFloor(Fragment, Result, bSuccess, Remaining);

			if (Remaining != 0)
			{
				Result->AddStatTagStack(TAG_Lyra_Inventory_Item_Count, Remaining);
			}
		}
		if (IsUsingRegisteredSubObjectList() && IsReadyForReplication() && Result)
		{
			AddReplicatedSubObject(Result);
		}
	}
	return Result;
}```
````

---

<div class="post-metadata">

**Author:** ![Chevidal451](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chevidal451](https://forums.unrealengine.com/u/Chevidal451)\
**Post date:** [February 27, 2025, 9:42am UTC](https://forums.unrealengine.com/t/tmap-not-working-on-client-in-online-replication/2361157/7 "2025-02-27T09:42:15Z")

</div>

sometimes it says 60 and sometimes it says 0, like I dont know whats going on. But it is more often to see the 0 than the 60. The few times the right value appears it is in the first execution of the game once u open the engine

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [March 6, 2025, 11:29am UTC](https://forums.unrealengine.com/t/tmap-not-working-on-client-in-online-replication/2361157/8 "2025-03-06T11:29:21Z")

</div>

> [@Chevidal451](#):
>
> sometimes it says 60 and sometimes it says 0

I think you have a context problem (you probably have some values ​​on the server and others on the client).

Use `HasAuthority()` function and handles data on one side only. (On the server if you are handling replicated variables). The client can only read.

---

<div class="post-metadata">

**Author:** ![Rev0verDrive](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rev0verdrive/32/907214_2.png) [@Rev0verDrive](https://forums.unrealengine.com/u/Rev0verDrive)\
**Post date:** [April 23, 2025, 8:07pm UTC](https://forums.unrealengine.com/t/tmap-not-working-on-client-in-online-replication/2361157/9 "2025-04-23T20:07:56Z")

</div>

I need to add to this. `HasAuthority` works a bit different on Listen Server setups. Host client is the server, so logic that’s supposed to work just on server will always execute on the host client.

I use a custom macro for LS Switch has Authority.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/2/9/4290f81b4efaa2e80c36086b016f802d34df4877.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/f/e/6fe7770569b1220b85bfb006ae157f541c0af3c5.png)

---

<div class="post-metadata">

**Author:** ![ShadowBr0kerz](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shadowbr0kerz/32/1201558_2.png) [@ShadowBr0kerz](https://forums.unrealengine.com/u/ShadowBr0kerz)\
**Post date:** [October 21, 2026, 11:50am UTC](https://forums.unrealengine.com/t/tmap-not-working-on-client-in-online-replication/2361157/10 "2026-10-21T11:50:47Z")

</div>

that empty map on the client is expected because TMaps dont replicate, the client just has its own local copy while the server has the filled one.  
do all inventory writes on the server behind an authority gate and replicate the results down through replicated structs or subobjects, the client should only read.  
you can also try Blueprint Object Replication, a networking tool for Unreal Engine that models each inventory item as its own replicated object with repnotifies: [https://www.fab.com/listings/e26dcf07-7c78-4e67-8e56-272cf6df8021](https://www.fab.com/listings/e26dcf07-7c78-4e67-8e56-272cf6df8021)
