- Home /
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: https://assetstore.unity.com/packages/tools/integration/mobile-ads-gdpr-compliant-102892
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: https://assetstore.unity.com/packages/tools/utilities/obfuscator-free-89420
And the error still exists after I disable it.
Any idea?
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.
Answer by TheGameLearner · Jan 20 at 04:09 PM
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.
Your answer
Follow this Question
Related Questions
How to make a No Ads Button 0 Answers
Unity Video ads closing when player leaves app. 0 Answers
Cant add AirPush ads on IOS. 0 Answers
Unity ads Video only show 4-5 times 1 Answer
How to implement Admob Native Ads on a ScrollRect in Unity 2 Answers