(Unity version 2021.3.2f1 with Purchasing Package 4.5.1)
I recently started noticing a warning
“Unity In-App Purchasing requires Unity Gaming Services to have been initialized before use.”
…in the console, so I decided to add the following two lines of code at the start of the app (as per the documentation):
var options = new InitializationOptions().SetEnvironmentName("production");
await UnityServices.InitializeAsync(options);
After this change, I noticed that my app got slightly sluggish once every minute or so (e.g., when scrolling a list, it feels like the frame rate drops to single digits for 2-3 sec – nothing major, but aesthetically quite annoying, especially since it happens so often).
Investigating the issue, it turned out that the sluggishness always co-occurs with this debug message (in intervals of exactly 60 sec):
Flushed up to token index 34368, cache file is 981155B
Unity.Services.Analytics.Internal.Buffer:FlushToDisk()
Unity.Services.Analytics.Internal.<>c__DisplayClass13_0:b__1(Int64)
Hence, it looks like UnityServices schedules a cache flushing process every minute, during which my app becomes temporarily sluggish.
The thing is that I’m not even actively using Unity Analytics, but from what I understand, Google Admob requires In-App Purchases and In-App Purchases requires Unity Analytics.
Could any of the following be a functional solution?
-
Wait with the above initialization until a user goes to the purchase screen (this would solve it for >99% of the app sessions, as purchases are rare)
-
Initialize only the IAP-related Unity Services and skip all other services that supposedly get initialized - sadly, I couldn’t find any documentation on the configurability of the ‘options’ in the above code
Any other thoughts and suggestions are of course also very welcome. Thanks!