FlaxEngine / FlaxAPI

Old repository with C# Editor and C# API for creating games in Flax Engine

Home Page:https://flaxengine.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Programatically reimporting ContentItems

stefnotch opened this issue · comments

Issue description:

I attempted to automatically reimport files when their source file changes. However, sometimes, I was faced with the following error:

Assertion failed!
File: Engine\Content\Storage\FlaxStorage.cpp
Line: 1057

Expression: _chunksLock == 0

Steps to reproduce:

It's a bit hard to reproduce; usually it takes quite a number of edits in various files until the error occurs.

Also, after the error happens, this happens when I try to clean up the temporary files I created:
image

The following code seems to cause it.

BinaryAssetItem item = Editor.ContentDatabase.Find(SOMEPATH) as BinaryAssetItem;
if (FlaxEngine.Content.Load(item.ID) is BinaryAsset test)
{
    test.WaitForLoaded();
    test.Reimport();
}

Minimal reproduction project:

https://github.com/stefnotch/flax-auto-import-resources-plugin

Flax version: v0.2

I also attempted to reimport stuff like this

Editor.ContentImporting.Reimport(item); 

However, this causes the Import dialog to pop up every single time, which is rather inconvenient.

I'll probably use this for now:

public static ImportFileEntry CreateEntry(string url, string resultUrl, bool isBinaryAsset)

Thanks for the report! It's related to one of the issues with content files locking in C++ by async tasks. It should be fixed by the next update. Also, we could add API for importing assets from code via API without popups.

Ok, looking forward to the update! 😄

Also, we could add API for importing assets from code via API without popups.

That sounds pretty useful. So, I'd love to see that API get implemented. (Something like the current .Reimport(), but with an optional parameter showImportPopup = true would be nice.)

Ok, this works beautifully. Thank you!