Hi.
I’m not understanding why NetworkDictionary is exploding.
This code that is in a component on the spawned object:
Simple Server only list add
public class ResourceBehavior : NetworkedBehaviour
{
private NetworkedDictionary<string, int> m_NetIntResource = new NetworkedDictionary<string, int>();
public override void NetworkStart()
{
base.NetworkStart();
if(IsServer)
{
m_NetIntResource.Add("Test", 0);
}
}
}
Works fine when objects are spawned from the host. However when the client sends a server a message to spawn the same object using this function:
Server RPC
[ServerRPC]
private void Server_RequestAddActorToEvent(int objectToSpawnID, Vector3 position, Quaternion rotation)
{
RecordContent actor = Database.Instance.GetRecordActor(objectToSpawnID);
//ServerCreateActor.
#if GBSERVER
GamePlayer.GetLocal.CurrentEditModeEncounter.Value.Edit_AddActor(actor as RecordActor, position, rotation);
#endif
}
The client gets the following error. I don’t see how I’m adding a key twice. It should ONLY be adding on the server. I’ve put logs in and far as I can tell nothing I’m doing is adding this key twice. What am I missing?
Call Stack
ArgumentException: An item with the same key has already been added. Key: Test
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <9577ac7a62ef43179789031239ba8798>:0)
MLAPI.NetworkedVar.Collections.NetworkedDictionary`2[TKey,TValue].ReadDelta (System.IO.Stream stream, System.Boolean keepDirtyDelta) (at <19597f6ed6a54f65b071432411566fd3>:0)
MLAPI.NetworkedBehaviour.HandleNetworkedVarDeltas (System.Collections.Generic.List`1[T] networkedVarList, System.IO.Stream stream, System.UInt64 clientId, MLAPI.NetworkedBehaviour logInstance) (at <19597f6ed6a54f65b071432411566fd3>:0)
MLAPI.Messaging.InternalMessageHandler.HandleNetworkedVarDelta (System.UInt64 clientId, System.IO.Stream stream, System.Action`2[T1,T2] bufferCallback, MLAPI.Messaging.Buffering.PreBufferPreset bufferPreset) (at <19597f6ed6a54f65b071432411566fd3>:0)
MLAPI.NetworkingManager.HandleIncomingData (System.UInt64 clientId, System.String channelName, System.ArraySegment`1[T] data, System.Single receiveTime, System.Boolean allowBuffer) (at <19597f6ed6a54f65b071432411566fd3>:0)
MLAPI.NetworkingManager.HandleRawTransportPoll (MLAPI.Transports.NetEventType eventType, System.UInt64 clientId, System.String channelName, System.ArraySegment`1[T] payload, System.Single receiveTime) (at <19597f6ed6a54f65b071432411566fd3>:0)
MLAPI.NetworkingManager.Update () (at <19597f6ed6a54f65b071432411566fd3>:0)