In our project, we’re streaming in Material assets using FStreamableManager::RequestAsyncLoad. After the load is complete, and the passed callback is invoked, we’re applying the loaded materials, one-by-one, onto a sphere mesh and then running USceneCaptureComponent2D::CaptureScene. Most of the materials render fine, but, occasionally, the resulting image has the default surface material (the WorldGridMaterial in our case) displayed on the mesh instead. Is that because the material in question isn’t fully loaded in some way? And, if so, is there any way to check that before CaptureScene is run?
Hi,
it’s possible that the materials have already loaded, but are still compiling. In that case you can try the following bit of code:
#include "AssetCompilingManager.h"
[...]
UMaterialInterface::SubmitRemainingJobsForWorld(GEngine->GetWorld());
FAssetCompilingManager::Get().FinishAllCompilation();
Alternatively, you could also try calling FlushAsyncLoading(), which will block until all pending packages are finished loading.
Another way that may work is by using FStreamableHandle::WaitUntilComplete(), which blocks until the requested assets have loaded. This pushes the requested asset to the top of the priority list, but does not flush all async loading.
TSharedPtr<FStreamableHandle> Handle = StreamableManager.RequestAsyncLoad(<SoftPtr>.ToSoftObjectPath());
Handle->WaitUntilComplete();
Let me know if this works,
Sam
No, surprisingly, that didn’t fix the issue. I also tried checking on the render thread that the FRenderProxy existed for the materials in question and that they weren’t the fallback one. We’re using Substrate materials in this project. Would that make a difference? Is there an extra step needed before those are ready to render?
Hi,
It’s possible that substrate materials need more time to compile due to their complexity, but that does not explain why none of those methods work. Substrate in 5.5 (and 5.6) is still in beta and under active development, so this may be a bug.
Do you see the same behaviour when opening the project in 5.6? Would you be able to provide a minimal repro scene, so I can investigate further?
Thanks,
Sam