Need help with an error - Exception OnEvent

Caught exception in OnEvent() for event code 200: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

I have a multiplayer game that works flawlessly when playing with in-game bots - but as soon as there are 2 players connected - I am getting OnEvent error above - full console log is attached below.

It just occurs on random instances - tried debugging it for 2 days - my head will explode. When I play 1v1 on a test, i think it's mostly connected to when I kill someone or I get killed - but it is completely random.

Unity version: 2020.3.19f1

PUN version: 2.39


  • sounds rough. in LoadBalancingPeer.cs it says event code 200 is regarding plugin versions. not sure what that's about.

    what kind of logging/print statements do you do for when players kill/are killed?

  • The current version of PUN 2.39 makes it more convoluted to handle errors in events, sorry. PUN 2.40 (eta this week) should revert to the better logging again.

    The problem is some exception in a RPC you call or rather receive in this case.

    If you wanted to, you could find the code of PUN 2, which calls the RPCs and then try/catch errors inside it. This will get you the proper callstack and help.

    As said: In PUN 2.40, we refined exception handling to throw the error that happened first within a number of DispatchIncomingCommands() calls. That hopefully is a good balance between getting the callstack and being able to dispatch more than one message a frame (which can cause bad delays).