Resolved: CurrentThreadIsMainThread() error for Asset Bundle LoadAllAssetsAsync

With Unity 2017.1.1, we are now receiving the following error while using LoadAllAssetsAsync.

Assertion failed: Assertion failed on expression: ‘Thread::CurrentThreadIsMainThread()’

    public IEnumerator LoadAssets(string bundleName)
    {
        this.assetsByBundle[bundleName] = new Dictionary<string, GameObject>();

        AssetBundle assetBundle = assetBundles[bundleName];
        AssetBundleRequest assetBundleRequest = assetBundle.LoadAllAssetsAsync<GameObject>();
        yield return assetBundleRequest;
        Object[] objects = assetBundleRequest.allAssets;
        foreach (GameObject gameObject in objects)
        {
            this.assetsByBundle[bundleName][gameObject.name] = this.assets[gameObject.name] = gameObject;
        }
    }

Edits:
Tested with Unity 2017.1.1p2; errors there too. Currently working great on 2017.1.0f3.

UPDATE:
This issue has been resolved in Unity patch 2017.2.0p2.

Been getting this same error on 1.1.f1, everything works but this error appears in log. Seems to sometimes disappear after unity restart.

Tested with 2017.2.0b8 and 2017.2.0b11, It seems like async loading AssetBundle that contains AnimationClip causes this error.

These functions are also affected

  • LoadFromFileAsync
  • LoadFromStreamAsync

Update

It works on 2017.2.0b5

I got the same probleme with 2017.1.1.f1.

Actually these functions doesn’t seems to matter. AssetBundle.LoadAssetAsync and AssetBundle.LoadAllAssetsAsync both causes this error.

Just +1 that i’m seeing the same thing when upgrading from a project that was 5.5.4 now to 2017.1.1f1 that utilizes AssetBundle.LoadAssetAsync the same errors occur.

I got the same probleme with 2017.1.1.p3.

I got the same probleme with 2017.2.0f1.

Assertion failed: Assertion failed on expression: ‘Thread::CurrentThreadIsMainThread()’
0x00000001411AC76B (Unity) StackWalker::GetCurrentCallstack
0x00000001411AF0FF (Unity) StackWalker::ShowCallstack
0x0000000141089420 (Unity) GetStacktrace
0x00000001405956C3 (Unity) DebugStringToFile
0x0000000140595EA1 (Unity) DebugStringToFile
0x00000001415F68CF (Unity) AnimationClip::BuildMecanimDataMainThread
0x00000001415F7993 (Unity) AnimationClip::Transfer<StreamedBinaryRead<0> >
0x00000001415FE37D (Unity) AnimationClip::VirtualRedirectTransfer
0x00000001409A57B8 (Unity) SerializedFile::ReadObject
0x000000014098BE4F (Unity) PersistentManager::ReadAndActivateObjectThreaded
0x000000014098DE8A (Unity) PersistentManager::LoadObjectsThreaded
0x00000001406B71DD (Unity) LoadSceneOperation::Perform
0x00000001406B6890 (Unity) PreloadManager::ProcessSingleOperation
0x00000001406B69FD (Unity) PreloadManager::Run
0x00000001406B7667 (Unity) PreloadManager::Run
0x00000001407B1918 (Unity) Thread::RunThreadWrapper
0x0000000076B359CD (kernel32) BaseThreadInitThunk
0x0000000076DAA561 (ntdll) RtlUserThreadStart

Hey everyone! I created a bug ticket and Unity wrote me today saying it’s a duplicate issue that’s being worked on. Please have a look and vote on the issue. Thanks!

https://issuetracker.unity3d.com/issues/loading-an-asset-that-has-an-animator-component-from-an-asset-bundle-with-loadasync-throws-assertion-failed-error

PS - In the meantime, an alternative that we are exploring is adding the Animator to the necessary GameObjects at runtime. When I’m able to test, I will report my results here.

How can a scenario such as loading assets from an asset bundle be so fundamentally broken in a major release version ??

I know you are not really looking for an answer and just want it fixed, however, creating a build of a user’s project data, and ensuring everything builds and loads correctly is a terribly complex problem. I’m giving a talk at Unite Austin that goes into the details of this for those that want more insight, and If you or others may find it interesting, we can see if we can adding the talk to the https://youtube.com/user/Unity3D channel. Just be warned it will be an hour long talk by me, and may be boring (I hope not though).

In this specific case, this issue was caused by fixing another bug to ensure AnimationClip data was actually being written out to disk correctly for asset bundles to be used by the player. The result though is that if you load that AnimationClip data from an asset bundle in the Editor using Async api’s, then it would trigger this assert. So this issue only will occur in the Editor and has no impact on the Player.

3 Likes

I will definitely check out that session once it’s posted on YouTube.

I am aware of the fact that certain things are very complex, but i would assume there are tests you perform before a release. In fact, the subject of automated tests has been discussed in the Unity blog so many times, one would only assume that there’s a test case for this specific thing.

Sadly AssetBundles working in the editor is one of those things we can’t have 100% test coverage, simply for the fact that AssetBundles built with the BuildPipeline API contain only Player specific data and the Editor can’t read everything that is Player specific. Interestingly enough, the build pipeline rewrite (target 2018.1 release) we have experimented with the option of allowing Editor specific asset bundles to be built, it works quite well, but won’t be part of the 2018.1 release as we wanted to focus on Player building bugs first.

4 Likes

FYI today I had some time to review and created a script that references the Animation Controller and Avatar for each asset and removed the Animator. Then in my main project, I check for this script and replace with Animator. Same errors occur. My understanding now is that this AssetBundle error is related specifically to either the Animation Controller, Avatar, or both.

Close, it’s serialized AnimationClip objects that trigger it.

2 Likes

Do we have a confirmed ‘fixed in’ version for this, or is it still unfixed? - there seem to be conflicting reports here about it working or not in 2017.2 builds?

(Definitely been seeing it all the time in 2017.1.0p4 and 2017.1.1f1, haven’t tried newer versions yet)

I have tried 2017.2 and the problem still persists… no sign of a fix for now…

1 Like

I’m getting a possibly-related issue where if I rapidly load/unload assets from bundles, things explode more spectacularly - A load of exceptions along the line of “CheckConsistency: GameObject does not reference component Transform. Fixing.”, and fragments of prefab being dumped in the root of the hierarchy…

This is when rapidly cycling through character models that are loaded async from bundles (mashing the next/previous character button as fast as possible), and it doesn’t seem related to a specific bundled prefab. I’m pretty sure I’ve fixed the initial issue of attempting to unload a character/bundle before the async load was complete - and currently out of ideas as to what causes this. The existing spam of internal Unity assertion messages doesn’t inspire confidence in the stability of the AssetBundle system, though… especially after spending a chunk of time trying to fix the reference counting in AssetBundleManager…

@bluescrn & @mbianchini

See the issue ticket. It’s been fixed for a future release. https://issuetracker.unity3d.com/issues/loading-an-asset-that-has-an-animator-component-from-an-asset-bundle-with-loadasync-throws-assertion-failed-error