We have encountered a problem where asset importing stopped working in certain situations. This happens with both automatic and manual reimporting.
It can be reproduced was as follows:
- Open a big level through the Content Browser. (I think the reason that it should be a big level is that the level is loaded asynchronously when opened)
- Navigate to a texture in the content browser that is referenced by one of the Actors in the level that was just opened.
- Right-click on that texture and choose “Reimport”
- Observe that a file selection window opens instead of the expected behaviour where the import is started.
A debug session showed that the SourceData variable in UAssetImportData for the broken assets wasn’t set. This value is supposed to be set in the UAssetImportData::Serialize function. However, this function is not always being called.
Some more investigation showed that the reason Serialize is not called is that the RF_NeedLoad flag is is not set on the UAssetImportData object.
It was observed that the AssetImportData was loaded properly when it was used in a small level. The reason for the different behaviour is a branch in FLinkerLoad::CreateExport. Somewhere in the middle of the function there is the following piece of code:
if(FPlatformProperties::RequiresCookedData()
|| IsAsyncLoading()
|| Export.bForcedExport
|| LinkerRoot->ShouldFindExportsInMemoryFirst()
)
Here we see a branch that is entered when AsyncLoading is enabled.
In this branch the RF_NeedLoad flag is only being set under certain conditions:
if (!Export.Object->HasAnyFlags(RF_LoadCompleted) &&
(Export.Object->HasAnyFlags(RF_DefaultSubObject) || (ThisParent && ThisParent->HasAnyFlags(RF_ClassDefaultObject))))
{
Export.Object->SetFlags(RF_NeedLoad | RF_NeedPostLoad | RF_NeedPostLoadSubobjects | RF_WasLoaded);
}
At this point the only flag set on the UAssetImportData object is RF_Async.
In UTexture::PostInitProperties it can indeed be observed that the UAssetImportData is constructed without any flags.
At this point I am not sure how to properly solve the problem. I am pretty certain the RF_NeedLoad flag needs to be set on the UAssetImportData objects somehow. But I don’t understand the system well enough to decide how that should be achieved.
So, my question would be if someone is familiar with this system and can help me fix it, tell me if I’m looking in the right direction, or is this maybe a known issue that is already being worked on?