#Hey guys,
1 messages · Page 1 of 1 (latest)
The error seems straightforward, you need to make sure that the services are properly initialized before trying to access the analytics singleton
I got that FROM initializing on WebGL. Seems like a potential bug because init works in Editor and standalone but fails in WebGL potentually due to the Init function being a Task
Opened a forum topic because I think it's a bug in the Analytics SDK.
Additional context:
using System.Collections;
using System.Collections.Generic;
using Unity.Services.Analytics;
using Unity.Services.Core;
using UnityEngine;
public class CustomEvents : MonoBehaviour
{
public static CustomEvents instance;
private void Awake()
{
instance = this;
// Initialize UGS
UnityServices.InitializeAsync();
}
private void Start()
{
// Initiate Analytics
AnalyticsService.Instance.StartDataCollection();
}
Works fine outside of WASM
The stacktrace indicates you were trying to access AnalyticsService.Instance which throws the ServicesInitializationException if it has not been initialized.
You do not check that the initialization is completed, it is a task
Just a second
Browsers run on a single thread though and 2022 doesn't support multi-threading outside of ThreadPather for async
Checking this now
you can check the state with UnityServices.State
Interesting
Tasks run on a single thread
I don't mean to be rude but are you sure sure, because I can lock up my window real quick with a Task haha
But it may explain the difference in behaviour between editor & webgl where it most likely always ends in time before the Start in editor
So we're assuming it needs more time ay
Yes, our tasks that send web requests need to happen on the main thread as that is a requirement of unity web request.
Tasks always run in the current synchonization context, it will run on the current thread unless specified otherwise (or using Task.Run)
Alright full sending:
// Initiate Analytics
Invoke(nameof(AnalyticsService.Instance.StartDataCollection), 5f);
``` 🤣
For additional context I used OG analytics and then the new beta analytics pre this update and it all worked fine in WebGL
Stability would nice with Unity products
@finite prairie I get the same error. This doesn't make any sense.
Even giving it ample time doesn't initialize it.
The issue lies here:
// Initialize UGS
UnityServices.InitializeAsync();
It literally just does not work in WebGL.
Are you seeing an exception around the initialization? Can you validate the state?
You should be awaiting the task completion
Alright I got it working.
I just moved the initialization to my entry point which gave it a lot more time to initialize and it seems okay.
I do think it's worth updating the documentation with this information though just to make it super clear that WebGL and standalone don't work the same for this particular service (As with most things WebGL v Standalone)