Hard object reference to DataAsset is sometimes null in packaged build

We are seeing problems with some actors in our levels that have Hard Object References to DataAssets. The references to the DataAsset references are showing up as null on occasion on cooked builds but never in the editor. The behavior is not consistent. Sometimes after a bit of work in the editor, the references start resolving to the correct assets again.

At a loss as to what might explain this. Documentation suggests that hard object references should be pretty foolproof. My best guess is that this is either a serialization issue or a cooker issue. Is there anyone who can shed some light on this? Or suggest some strategies for debugging this?

I’ve exactly the same problem ! References to my Data Assets works in editor but in builds they’re set to null. It only happen when when I open a new map tho. If I load the map with the DataAssets first, references are ok.

Can anyone help please ?

[UE 4.25.3]

Built engine from source and tracked down the source of this issue in my case. Epic has a bug report for it: Unreal Engine Issues and Bug Tracker (UE-103849)

Anyone managed to fix this? On the ticket it says

"The licensee-identified workaround is to have FLinker expose it’s imports to the GC reference system so they will get fixed up during the reinstance pass, but this may conflict with other BP compile on load problems. "

Presumably just wrap those in a UPROPERY?

I haven’t been able to. Hoping someone from epic can post a code snippet. Modifying the blueprint compiler is a bit beyond my abilities. I’m not sure how I would go about exposing FLinker to the GC. I believe (and take this with a grain of salt, I have yet to test this) that ensuring your DataAssets do not inherit from a blueprint parent is a workaround for this issue. Without a blueprint parent, the DataAsset will not get reinstanced. However, this is not a great option for us. We’re a designer heavy team and we would like to give our designers the freedom to rapidly prototype without writing C++ code.

Bump this topic so hard.

I know this is months later, but in case anyone else runs into something like this, I had a similar but not quite the same problem.

Given the code:

LoadClass<MyClass>(NULL, DataAssetPath);

In this scenario the UDataAsset at DataAssetPath was not of class MyClass. This results in a failed package load on the backend and Unreal will add that asset path as a “Known Missing Package” and skip over loading that UDataAsset in any case there on out including valid attempts.

// Stop future repeated warnings
FLinkerLoad::AddKnownMissingPackage(FName(*InOuter->GetPathName()));

which gets referenced in FAsyncPackage::LoadImports_Event:

// Don't try to import a package that is in an import table that is an invalid entry
if (FLinkerLoad::IsKnownMissingPackage(!Import->HasPackageName() ? Import->ObjectName : Import->GetPackageName()))
{
   continue;
}

Which causes the data asset reference to be null on new spawned actors. This is also why the first time a map booted, all the references were intact. It wasn’t until after the logic that called LoadClass processed, that the packages were lost in subsequent actors.

The solution then is to make sure that when LoadClass is used, ensure that the asset path is of that class. I suggest trying to load the asset as an object with LoadObject and get/verify the class from that via casting.