Error: IsObjectMonoBehaviour can only be called from the main thread.

I am using Gley Mobile Ads to show rewarded video and then run the callback function in my Android app. And the callback function is only setting a class boolean variable.

Gley Mobile Ads: Mobile Ads (GDPR & iOS 14.5 Compliant) | Integration | Unity Asset Store

But when the advertise is finished (either complete or incomplete), the error comes out and it does not run the callback function even if I try to catch the exception.

I think it may be related to another plugin Obfuscator Free as it will check for MonoBehavior when packing into .apk but I am not sure:

And the error still exists after I disable it.

Any idea?

127994-screenshot-2018-11-19-at-51631-pm.png

Did you find the answer? I am getting same error on loading my game after adding google admob to the project.

Where do you run playAdTV from? It can't be done from other than the main thread probably? Unity is sensitive for that, some (many) things cannot be threaded.

1 Answer

1

I was getting the error on the development build. I solved it by changing all function tasks inside callbacks as a separate function.

When I get a callback from my ads now, an empty function stores all parameters in local variables of the script and sets a predefined bool as true, then on Update(), the bool being true calls the originally intended function with all local variables as parameters as the callback should have worked originally. This ensured my callbacks ran on the main thread and not in callback methods.

I believe there might be a better answer available, but this worked for me so I thought to share here, please add other answers if you know a better solution.