Hello,
I have implemented AdMob and added google Consent screen according to official documentation (https://developers.google.com/admob/unity/privacy). On the first run, when user have to comply with gdpr etc. I am getting this error when granting reward:
2024.03.08 09:43:51.331 27565 27922 Error Unity UnityException: get_isActiveAndEnabled can only be called from the main thread.
2024.03.08 09:43:51.331 27565 27922 Error Unity Constructors and field initializers will be executed from the loading thread when loading a scene.
2024.03.08 09:43:51.331 27565 27922 Error Unity Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
2024.03.08 09:43:51.331 27565 27922 Error Unity at TMPro.TextMeshProUGUI.SetVerticesDirty () [0x00000] in <00000000000000000000000000000000>:0
2024.03.08 09:43:51.331 27565 27922 Error Unity at TMPro.TMP_Text.set_text (System.String value) [0x00000] in <00000000000000000000000000000000>:0
2024.03.08 09:43:51.331 27565 27922 Error Unity at Assets._GAME_.GUI.UpgradeButton.Setup () [0x00000] in <00000000000000000000000000000000>:0
2024.03.08 09:43:51.331 27565 27922 Error Unity at Assets._GAME_.Ads.RewardedAdUnit+<>c__DisplayClass16_0.<Show>b__0 (GoogleMobileAds.Api.Reward reward) [0x00000] in <00000000000000000000000000000000>:0
2024.03.08 09:43:51.331 27565 27922 Error Unity at GoogleMobileAds.Api.RewardedAd+<RegisterAdEvents>c__AnonStorey4.<>m__0 () [0x00000] in <00000000000000000000000000000000>:0
2024.03.08 09:43:51.331 27565 27922 Error Unity at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection
I thought that this piece, where calling initialize in callback might be the problem:
ConsentForm.LoadAndShowConsentFormIfRequired((FormError formError) =>
{
if (formError != null)
{
// Consent gathering failed.
UnityEngine.Debug.LogError(consentError);
return;
}
// Consent has been gathered.
if (ConsentInformation.CanRequestAds())
{
MobileAds.Initialize((InitializationStatus initstatus) =>
{
// TODO: Request an ad.
});
}
});
Of course I have configured MobileAds.RaiseAdEventsOnUnityMainThread = true;
But I also tried just setting flag and initializing ads in update method. But still getting the same error on the first game run. If I agree or disagree on the next app launch everything works fine.
Does anyone had similar problem?