Interop Wrapper causes Unity Crash


We are working on industrial simulation projects for which we need to communicate with hardware devices using interop wrapper (Com component).

For now this seems impossible as can be seen here and the problem is recurrent!

We spent a lot of time looking for a solution.

This seems to be an internal problem in Unity. Because everything works perfectly, when testing with a simple mono console application.

Do you have any solutions for this problem?

Thank you in advance,


Ensure that your interop does not Callback into unity (if its asyncronous or fed from external thread independent inputs)

Unity is not callback nor threadsafe, any access to classes that extend UnityEngine.Object is only allowed from within the same thread as unity scripts are running in, not asyncronous from other threads nor from asyncrnous callbacks from COM / OS async operations

If thats the case for you there are two possible ways:

  1. Write a wrapper that gets these callbacks and queues the stuff and then expose a function that allows unity to request the next event / dataobject or whatever in a blocking, unthreaded form
  2. Make the callbacks call into a static function on something extending from System.Object and write the same kind of logic as above to request the information on classes extending UnityEngine.Object