googleanalytics / google-analytics-plugin-for-unity

Google Analytics plugin for the Unity game creation system
Apache License 2.0
385 stars 140 forks source link

Function SoundChannelInstance *SoundChannel::operator->() const may only be called from main thread! #166

Open alaslipknot opened 6 years ago

alaslipknot commented 6 years ago

Hi,

Calling Reward Ads cause the game to crash and output this error :

Function SoundChannelInstance *SoundChannel::operator->() const may only be called from main thread! AppAdvisory.Ads.AAAdmob:OnAdOpeningRewarded(Object, EventArgs) System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) System.Reflection.MethodBase:Invoke(Object, Object[]) UnityEngine.AndroidJavaProxy:Invoke(String, Object[]) UnityEngine._AndroidJNIHelper:InvokeJavaProxyMethod(AndroidJavaProxy, IntPtr, IntPtr) 12-05 18:45:13.500 28685 28685 E Unity : [ line 21] (Filename: Line: 21)

After testing the game with an empty scene (no audioSource) the Ads worked properly and i got no error, so i had to come back to my game and :

for (int i = 0; i < musicSource.Length; i++) { musicSource[i].enabled = false; }

For a game that has a lot more than just one audioSource for music that are dynamic and running constantly, running that FindObjectsOfType every death is really not something that i usually do, so am wondering, is everyone aware of this issue ? why is AdMob reward ads cause unity to crash when its playing Audio while every other Ad network that i used in the past doesn't ?

Thanks!

gmikhail commented 6 years ago

I have the same problem. The complete disabling of the background sound helped (pause sound does not help). Unity 2018.1, Google Mobile Ads Unity Plugin v3.13.1.

gmikhail commented 6 years ago

Workaround: https://forum.unity.com/threads/unity-ad-2-0-4-crashes-playing-audio-after-rewarded.432359/#post-2796916