Android plugins and callbacks on non-scripting threads

We have a plugin that we “wrapped” and call into using the standard AndroidJavaClass and AndroidJavaObject classes.

Some of the methods accept callbacks, and for that we use the AndoidJavaProxy class, that is passed to the plugin code and gets invoked automagically by Unity.

The issue is, the callback is raised on an arbitrary thread (may be the UI thread or some other worker thread) that is NOT Unity’s scripting thread.

Is there any infrastructure for easily marshalling calls to the scripting thread (automatically) ?

Currently we have a scene object and we enqueue the callbacks on it. That object runs its Update() methods and raises the callbacks (on the scripting thread).

I am looking for a built-in and easy way of doing the same.

This is a good question.

In fact, I think that your solution

Currently we have a scene object and we enqueue the callbacks on it. That object runs its Update() methods and raises the callbacks (on the scripting thread).

is a good way to go. We do similar things in our Java code to post events to the main thread. Adding built-in infrastructure is complex and does not provide control when you want the callbacks to be called (in your code you can do it in Update() or at any convenient point).