Error when exporting scene

I am getting this error when exporting the scene, and nothing I do, restart, or clean build, fixes it.
UnityException: get_skinIndex can only be called from the main thread.

Hi Tomislav, it looks like the error

UnityException: get_skinIndex can only be called from the main thread

indicates that during export a Unity API (related to skinned mesh data) is being accessed from a background thread. Unity’s API for accessing skin indices isn’t thread-safe and must be called only from the main thread. This typically happens if a background (worker) thread is used during the export process—sometimes in custom scripts or even in parts of the export pipeline—and that thread calls into a SkinnedMeshRenderer’s properties.

To troubleshoot this issue you can:

• Check any custom scripts or components related to skinning or animation that might be running asynchronously. Make sure that any access to properties like get_skinIndex is done in main thread methods (for example within start() or update() of a Needle Engine Behaviour).

• If you’re using any multithreaded export features in your setup, consider disabling or wrapping those calls to queue the sensitive operations on the main thread.

• Verify that you’re running a recent version of both Unity and Needle Engine. Many such issues get fixed in newer releases. If you haven’t already, please use Unity’s ā€œCopy Project Info Into Clipboardā€ option so we can check for any version-specific problems.

Below is an example component that demonstrates how to safely access skin data on the main thread:

import { Behaviour, showBalloonMessage } from "@needle-tools/engine";
import { SkinnedMesh } from "three";

export class MainThreadSkinAccess extends Behaviour {
  update() {
    // This update loop runs on the main thread.
    // Traverse children to find SkinnedMesh objects and access their data safely.
    this.gameObject.traverse(child => {
      if (child instanceof SkinnedMesh) {
        // Access skin data (such as skin indices) safely here
        // Example: log a message when processing this skinned mesh
        console.log("Processing skinned mesh on main thread:", child.name);
      }
    });
  }
}

Using this approach, you can ensure that any Unity API requiring main thread access is queried within the main thread scope. If the problem persists after checking your code and exporting setup, please share additional project info (Unity version, Needle Engine version, and any custom export scripts) so we can help diagnose further.

Hope this helps!

4 replies left
thread_4meNuHj0QK1ig2Z70XWI5EQ6
Reply to this post directly if you need further help (bottom right button)

Hi, could you share the full stacktrace / full error message? Thank you

UnityException: get_skinIndex can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEditor.EditorGUIUtility.get_isProSkin () (at <4d62aeff85f745648163b49ed30bba78>:0)
Needle.Engine.Utils.LogHelpers.Highlight (System.String str) (at ./Library/PackageCache/com.needle.engine-exporter@fc9365729d1e/Common/Runtime/Utils/LogHelpers.cs:40)
Needle.Engine.Utils.LogHelpers..cctor () (at ./Library/PackageCache/com.needle.engine-exporter@fc9365729d1e/Common/Runtime/Utils/LogHelpers.cs:56)
Rethrow as TypeInitializationException: The type initializer for ā€˜Needle.Engine.Utils.LogHelpers’ threw an exception.
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) (at <314938d17f3848e8ac683e11b27f62ee>:0)
Needle.Engine.MenuItems.InternalExportAndBuildTask (Needle.Engine.Core.BuildContext buildContext) (at :0)
Needle.Engine.MenuItems.BuildForDistAsync (Needle.Engine.Core.BuildContext buildContext) (at ./Library/PackageCache/com.needle.engine-exporter@fc9365729d1e/Core/Editor/Actions/MenuItems.cs:356)
Needle.Engine.MenuItems.BuildForDist (Needle.Engine.Core.BuildContext buildContext) (at ./Library/PackageCache/com.needle.engine-exporter@fc9365729d1e/Core/Editor/Actions/MenuItems.cs:344)
System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) (at <314938d17f3848e8ac683e11b27f62ee>:0)
Needle.Engine.EnterPlayMode.Play (Needle.Engine.IProjectInfo info) (at :0)
Needle.Engine.EnterPlayMode.Play () (at ./Library/PackageCache/com.needle.engine-exporter@fc9365729d1e/Core/Editor/Actions/EnterPlayMode.cs:76)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) (at <314938d17f3848e8ac683e11b27f62ee>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <844019a3a067481c8d9cb70c7a2ba447>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <844019a3a067481c8d9cb70c7a2ba447>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <844019a3a067481c8d9cb70c7a2ba447>:0)

Thanks for the report.
Could you try updating the Unity package to 4.5.2 (e.g. via Window/Package Manager > Needle Engine)?

Ok, for now I don’t see that update yet.

Ok let me know when you tried it. It’s been published 20 minutes ago, perhaps try to click the refresh button in the Unity Package Manager window (the circular error in the bottom left).

You can also check the Needle Engine component at the bottom of the component if there’s the update button visible.

Now the error is gone, but I’ve noticed something else: no matter what color I choose for the loading background, it is always white.
In older builds this worked

<needle-engine
    loading-logo-src="./include/Holofiction-Solid-White-LOGO VERTICAL-TAGLINE.png" 
    loading-background-color="#222222" 
    loading-text-color="#fff">
  </needle-engine>

The attribute name has been changed to loading-background:

Attributes docs: <needle-engine> Configuration | Needle Engine Documentation

I see that loading-text-color is now removed. How do I change the loading text color, or is there no longer loading text?

The loading text has been removed as well so the attribute is deprecated

This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.