Textures sometimes fail to load in Unreal
Posted: 28 Sep 2023, 17:01
In Unreal we've moved the loading of the Xaml files from disk to be asynchronous. This is because we want to be able to load/unload them during gameplay - the motivation here is that unloading the Xaml means its textures get unloaded as well.
We initiate the async load like this:
Then when its loaded we call LoadXaml on it
The issue we're having is sometimes the textures for the Xaml fail to load with the error message:
Stepping through the code we can see that CreateTexture is failing because InTexture->GetResource() returns nullptr
The issue only occurs in a standalone build - never in editor - and seems to be timing related, sometimes it works fine sometimes it fails.
It looks like the textures haven't finished loading when CreateTexture tries to access them - the UTexture object exists but texture data doesn't yet
Any ideas what we can do to resolve it?
We initiate the async load like this:
Code: Select all
StreamableManager.RequestAsyncLoad(XamlObject.ToSoftObjectPath(), FStreamableDelegate::CreateRaw(this, &FViewLoader::OnXamlLoaded),
FStreamableManager::AsyncLoadHighPriority, false, false, "ViewLoader");Then when its loaded we call LoadXaml on it
Code: Select all
void FViewLoader::OnXamlLoaded()
{
UNoesisXaml* XamlFile = XamlObject.Get();
const Ptr<BaseComponent> Component = XamlFile->LoadXaml();
..
}Code: Select all
LogNoesis: Warning: Error loading '/Game;component/MyGame/Images/image_8.png', using fallback textureCode: Select all
Noesis::Ptr<Noesis::Texture> FNoesisRenderDevice::CreateTexture(UTexture* InTexture)
{
if (!InTexture || !InTexture->GetResource())
return nullptr;
..
}It looks like the textures haven't finished loading when CreateTexture tries to access them - the UTexture object exists but texture data doesn't yet
Any ideas what we can do to resolve it?