Need help on custom INetworkStruct, nested collections

Hi, guys.

So, I want to implement synced inventory and the source of truth here is the host. Fusion is in Hosted Mode. Just bear with me on this one, I want it to be like this.

So I want a structure equivalent to C#'s

Dictionary<int, List<string>>

In order to simulate this I have made this:

[Networked, Capacity(Globals.MAX_CLIENTS)]
private NetworkDictionary<int, int> PlayerToIndexMapping => default;

[Networked, Capacity(ITEM_LIMIT)]
private NetworkArray<NetworkString<_16>> player0Inventory => default;

[Networked, Capacity(ITEM_LIMIT)]
private NetworkArray<NetworkString<_16>> player1Inventory => default;

[Networked, Capacity(ITEM_LIMIT)]
private NetworkArray<NetworkString<_16>> player2Inventory => default;

[Networked, Capacity(ITEM_LIMIT)]
private NetworkArray<NetworkString<_16>> player3Inventory => default;

As you can see this is not a very good approach because of the boilerplate code I have to write and if I want to have more players I need to write more code.

I have tried with:

NetworkDictionary<int, NetworkArray<NetworkString<_16>>> inventory;

But I keep getting lots of Fusion's errors that are not really helpful to me, I assume nested NetworkArray is the problem cause it does not have Capacity defined.

How is INetworkStruct intended for use with nested collections?

Answers