Issues with UgcService.Instance.CreateContentAsync on WebGL: RuntimeError and Function Signature Mismatch

Hi Unity community,

I’ve encountered an issue with UgcService.Instance.CreateContentAsync when running my Unity project on WebGL. The code works perfectly in the editor but fails during execution on WebGL. Here’s the detailed description of the problem:


Problem Overview:
When executing the following coroutine:

Task<Content> content;  

try  
{  
    content = UgcService.Instance.CreateContentAsync(new CreateContentArgs(  
        name,  
        $"MicroGame: {selectedMicrogame} ModuleId: {selectedModuleId}",  
        contentStream  
    )  
    {  
        IsPublic = true,  
        Metadata = newMetadata.ToJson()  
    });  
}  
catch (Exception e)  
{  
    Debug.LogError(e.Message);  
    yield break;  
}

I get the following error on WebGL:

Invoking error handler due to
RuntimeError: null function or function signature mismatch
at il2cpp::icalls::mscorlib::System::Runtime::InteropServices::Marshal::PtrToStructure

The error appears after the coroutine logs some extra info, indicating that the upload process is partially initialized but fails before completion.


Observations:

  1. The issue is specific to WebGL; the same logic works without any problems in the Unity Editor.
  2. The coroutine halts after a few frames, not directly.
  3. It seems the error originates from UgcService.Instance.CreateContentAsync.

Questions:

  1. Are there known limitations with UgcService.Instance.CreateContentAsync on WebGL?
  2. Could this be related to threading or memory management on WebGL, considering the use of Task and MemoryStream?
  3. Are there any recommended workarounds or best practices to address this issue on WebGL?

Any insights or guidance would be greatly appreciated!

Thanks in advance for your help.

1 Like

You are calling an async method without awaiting it. Add the await keyword.

Is that because WebGL does not support threading? Calling an async method without await should theoretically be fine, right?

All async methods should be awaited. I’m not sure how it works internally or what the side effects are if you don’t. It’s just generally good practice to await async methods. Even the IDE will warn that the call isn’t awaited. I believe normally this will simply block the caller if await is omitted but …

async/await work on the web but they work differently hence the effect you see. You can no longer expect an async call to return instantly. Even if it is the very first Services.InitializeAsync and you instantly follow that with another service call then you’ll get a “not initialized” exception on the web unless you add the await keyword.

Task.Delay() is the only method that won’t work on the web to my knowledge but there may be others, specifically any Task method that creates or uses background threads won’t work.

I want to resurface this because im getting the same error on the same UGC Service on Web. CreateContentAsync works fine but DownloadContentDataAsync doesn’t for me.

Error: RuntimeError: null function or function signature mismatch
Platform: Web/WebGPU
Unity Editor version: 6000.0.31f1

The method the error happens:
await UgcService.Instance.DownloadContentDataAsync(content, downloadContent: true, downloadThumbnail: false);

Does Ugc Service not work on web? Anyone else running into this issue?

Ill make another post since this is kinda unrelated.

1 Like