FishNet
FishNet copied to clipboard
In a SyncDictionary, having the Key as a SyncVar class will throw the given key was not present
Hey @FirstGearGames , I don't know if this is a bug, intentional, or there is a workaround.
If you create a SyncDictionary like the one in the example, when you check the key, the client will throw an error saying that the key was not present (will work just fine in the server - host, I guess that it's because it has the original class).
I will provide an example so you can test it:
`using Axvemi.Players; using FishNet.Object; using FishNet.Object.Synchronizing; using UnityEngine; using UnityEngine.InputSystem;
namespace Axvemi.Networking {
public class MyCustomClass
{
public int id;
public string name;
public MyCustomClass(int id, string name) {
this.id = id;
this.name = name;
}
public MyCustomClass() { }
}
public class ClientInstance : NetworkBehaviour
{
[SyncVar]
public MyCustomClass MyCustomClass;
[SyncObject]
public readonly SyncDictionary<MyCustomClass, string> TestingDictionary = new();
#region FISHSNET
public override void OnStartServer()
{
base.OnStartServer();
ClientInstances.Add(this);
MyCustomClass = new MyCustomClass(1, "My name");
TestingDictionary[MyCustomClass] = "Value of the dictionary";
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.F3))
{
Debug.Log(MyCustomClass);
Debug.Log(TestingDictionary[MyCustomClass]);
}
}
}
}`
If you could provide some insigh on this I would appreciate it.
<3