TMap replication still not supported?

I am posting this in case it might be useful as a simple starting place for someone. Tested in 4.19 only, and only for simple types (ie. FString). The TMAP is placed inside of a USTRUCT where NetSerialize moves key/values between TMAP and TARRAY’s before/after network transport.

USTRUCT(BlueprintType)
struct FStructWithMap
{
	GENERATED_BODY()
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
    TMap<FString, FString> StringMap;
 
    TArray<FString> StringKeys;
    TArray<FString> StringValues;


	bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess)
	{
		if (Ar.IsLoading())
		{
			// Move data to Map
			Ar << StringKeys;
			Ar << StringValues;
			for (auto It = StringKeys.CreateConstIterator(); It; ++It)
			{
				StringMap.Add(StringKeys[It.GetIndex()], StringValues[It.GetIndex()]);
			}
		} else {
			// Move data to Arrays
			StringMap.GenerateKeyArray(StringKeys);
			StringMap.GenerateValueArray(StringValues);
			Ar << StringKeys;
			Ar << StringValues;
		}
		StringKeys.Empty();
		StringValues.Empty();

		bOutSuccess = true;
		return true;
	}
};
 
template<>
struct TStructOpsTypeTraits<FStructWithMap> : public TStructOpsTypeTraitsBase2<FStructWithMap>
{
	enum
	{
		WithNetSerializer = true
	};
};
4 Likes