When using a event with a non-monobehavior it gets triggered twice on invoke.
public class ClassA
{
public event EventHandler ontest;
private static ClassA _instance;
private static readonly object _lock = new object();
public static ClassA Instance
{
get
{
lock (_lock)
{
if (_instance == null)
{
_instance = new ClassA();
}
return _instance;
}
}
}
public void triggerTest()
{
ontest?.Invoke(this, EventArgs.Empty);
}
}
public class ClassB : MonoBehaviour
{
private void Awake()
{
ClassA.Instance.ontest += testEvent;
ClassA.Instance.triggerTest();
}
public void testEvent(object sender, EventArgs e)
{
Debug.Log("Test Event triggered!");
}
}
I’m using a OnPlayerConnected Event, wich adds dummies for every player except the new player. The server send a packet wich gets received by the new player, this client willl then send a nother packet to every client. When it gets received it will trigger this event: here I noticed that there are always two calls. I have traced it back, but it also happens with the example code above. Is there something about UnityTransport and Events or…?