#Hey guys,

1 messages · Page 1 of 1 (latest)

finite prairie
#

The error seems straightforward, you need to make sure that the services are properly initialized before trying to access the analytics singleton

dry torrent
#

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

finite prairie
#

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

dry torrent
#

Just a second

dry torrent
#

Checking this now

finite prairie
#

you can check the state with UnityServices.State

dry torrent
#

Interesting

finite prairie
#

Tasks run on a single thread

dry torrent
#

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

finite prairie
#

But it may explain the difference in behaviour between editor & webgl where it most likely always ends in time before the Start in editor

dry torrent
#

So we're assuming it needs more time ay

finite prairie
#

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)

dry torrent
#

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.

finite prairie
#

Are you seeing an exception around the initialization? Can you validate the state?
You should be awaiting the task completion

dry torrent
#

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)