I just came across this. Glad I’m not the first but it’s disappointing that there’s been no official response in this time.
Is there a restriction on the type of object that can be passed through an event? Originally, I wanted to use C#'s EventHandler:
[SyncEvent]
public event System.EventHandler EventMatchEvent;
But this gives the following error:
UNetWeaver error: Exception :System.ArgumentException: Member ‘System.EventArgs’ is declared in another module and needs to be imported.
I assume that is something that Unity devs would have to deal with, so I made my own delegate instead:
public delegate void MatchEventDelegate( object sender, MyEnum enumValue, object data );
[SyncEvent]
public event MatchEventDelegate EventMatchEvent;
But no matter what I passed as data, on the receiving end, the data wasn’t able to be cast, causing a cast exception every time.
I thought maybe it was the type of object being passed so I just passed the value of a NetworkIdentity.netId, just a native uint, but in the end, even that couldn’t not be cast from object.
Finally, I tried by changing the last argument of my delegate to uint and that worked but that’s not helpful if I have to create a handful of delegates and events just to cover all the data I might want to pass for an event.
Ultimately, it seems like there is just a problem with serialization/deserialization across the network when casting to object.
Is this something that is bug worthy, or is this by design and the documentation is just lacking?