Fix shader graph assets loading to wait for async task

#3802
This commit is contained in:
Wojtek Figat
2025-11-18 16:11:31 +01:00
parent de9e282bad
commit 2ca435a414
5 changed files with 16 additions and 14 deletions

View File

@@ -18,7 +18,7 @@ public:
/// <param name="id">The asset id.</param>
/// <returns>Loaded asset of null.</returns>
template<typename T>
T* LoadAsync(const Guid& id)
T* Load(const Guid& id)
{
for (auto& e : *this)
{
@@ -26,8 +26,10 @@ public:
return (T*)e.Get();
}
auto asset = (T*)::LoadAsset(id, T::TypeInitializer);
if (asset)
if (asset && !asset->WaitForLoaded())
Add(asset);
else
asset = nullptr;
return asset;
}

View File

@@ -425,8 +425,8 @@ void ParticleEmitterGPUGenerator::ProcessGroupParticles(Box* box, Node* node, Va
case 300:
{
// Load function asset
const auto function = Assets.LoadAsync<ParticleEmitterFunction>((Guid)node->Values[0]);
if (!function || function->WaitForLoaded())
const auto function = Assets.Load<ParticleEmitterFunction>((Guid)node->Values[0]);
if (!function)
{
OnError(node, box, TEXT("Missing or invalid function."));
value = Value::Zero;
@@ -439,7 +439,7 @@ void ParticleEmitterGPUGenerator::ProcessGroupParticles(Box* box, Node* node, Va
{
if (_callStack[i]->Type == GRAPH_NODE_MAKE_TYPE(14, 300))
{
const auto callFunc = Assets.LoadAsync<ParticleEmitterFunction>((Guid)_callStack[i]->Values[0]);
const auto callFunc = Assets.Load<ParticleEmitterFunction>((Guid)_callStack[i]->Values[0]);
if (callFunc == function)
{
OnError(node, box, String::Format(TEXT("Recursive call to function '{0}'!"), function->ToString()));
@@ -514,7 +514,7 @@ void ParticleEmitterGPUGenerator::ProcessGroupFunction(Box* box, Node* node, Val
value = Value::Zero;
break;
}
const auto function = Assets.LoadAsync<ParticleEmitterFunction>((Guid)functionCallNode->Values[0]);
const auto function = Assets.Load<ParticleEmitterFunction>((Guid)functionCallNode->Values[0]);
if (!_functions.TryGet(functionCallNode, graph) || !function)
{
OnError(node, box, TEXT("Missing calling function graph."));

View File

@@ -50,8 +50,8 @@ MaterialLayer* MaterialGenerator::GetLayer(const Guid& id, Node* caller)
}
// Load asset
Asset* asset = Assets.LoadAsync<MaterialBase>(id);
if (asset == nullptr || asset->WaitForLoaded(10 * 1000))
Asset* asset = Assets.Load<MaterialBase>(id);
if (asset == nullptr)
{
OnError(caller, nullptr, TEXT("Failed to load material asset."));
return nullptr;

View File

@@ -285,8 +285,8 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
case 24:
{
// Load function asset
const auto function = Assets.LoadAsync<MaterialFunction>((Guid)node->Values[0]);
if (!function || function->WaitForLoaded())
const auto function = Assets.Load<MaterialFunction>((Guid)node->Values[0]);
if (!function)
{
OnError(node, box, TEXT("Missing or invalid function."));
value = Value::Zero;
@@ -299,7 +299,7 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
{
if (_callStack[i]->Type == GRAPH_NODE_MAKE_TYPE(1, 24))
{
const auto callFunc = Assets.LoadAsync<MaterialFunction>((Guid)_callStack[i]->Values[0]);
const auto callFunc = Assets.Load<MaterialFunction>((Guid)_callStack[i]->Values[0]);
if (callFunc == function)
{
OnError(node, box, String::Format(TEXT("Recursive call to function '{0}'!"), function->ToString()));
@@ -808,7 +808,7 @@ void MaterialGenerator::ProcessGroupFunction(Box* box, Node* node, Value& value)
value = Value::Zero;
break;
}
const auto function = Assets.LoadAsync<MaterialFunction>((Guid)functionCallNode->Values[0]);
const auto function = Assets.Load<MaterialFunction>((Guid)functionCallNode->Values[0]);
if (!_functions.TryGet(functionCallNode, graph) || !function)
{
OnError(node, box, TEXT("Missing calling function graph."));

View File

@@ -704,8 +704,8 @@ void ShaderGenerator::ProcessGroupTools(Box* box, Node* node, Value& value)
case 16:
{
// Get the variable type
auto asset = Assets.LoadAsync<GameplayGlobals>((Guid)node->Values[0]);
if (!asset || asset->WaitForLoaded())
auto asset = Assets.Load<GameplayGlobals>((Guid)node->Values[0]);
if (!asset)
{
OnError(node, box, TEXT("Failed to load Gameplay Global asset."));
value = Value::Zero;