| 238 | } |
| 239 | |
| 240 | void FPCGExContext::LoadAssets() |
| 241 | { |
| 242 | if (bAssetLoadRequested) { return; } |
| 243 | bAssetLoadRequested = true; |
| 244 | |
| 245 | SetAsyncState(PCGEx::State_LoadingAssetDependencies); |
| 246 | |
| 247 | if (!RequiredAssets || RequiredAssets->IsEmpty()) |
| 248 | { |
| 249 | bAssetLoadError = true; // No asset to load, yet we required it? |
| 250 | return; |
| 251 | } |
| 252 | |
| 253 | if (!bForceSynchronousAssetLoad) |
| 254 | { |
| 255 | PauseContext(); |
| 256 | |
| 257 | // Dispatch the async load request to the game thread |
| 258 | TWeakPtr<FPCGContextHandle> CtxHandle = GetOrCreateHandle(); |
| 259 | |
| 260 | if (IsInGameThread()) |
| 261 | { |
| 262 | LoadHandle = UAssetManager::GetStreamableManager().RequestAsyncLoad( |
| 263 | RequiredAssets->Array(), [CtxHandle]() |
| 264 | { |
| 265 | if (FPCGExContext* NestedThis = GetContextFromHandle<FPCGExContext>(CtxHandle)) { NestedThis->UnpauseContext(); } |
| 266 | }); |
| 267 | |
| 268 | if (!LoadHandle || !LoadHandle->IsActive()) |
| 269 | { |
| 270 | UnpauseContext(); |
| 271 | |
| 272 | if (!LoadHandle || !LoadHandle->HasLoadCompleted()) |
| 273 | { |
| 274 | bAssetLoadError = true; |
| 275 | CancelExecution("Error loading assets."); |
| 276 | } |
| 277 | else |
| 278 | { |
| 279 | // Resources were already loaded |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | else |
| 284 | { |
| 285 | AsyncTask( |
| 286 | ENamedThreads::GameThread, [CtxHandle]() |
| 287 | { |
| 288 | FPCGExContext* This = GetContextFromHandle<FPCGExContext>(CtxHandle); |
| 289 | if (!This) { return; } |
| 290 | |
| 291 | This->LoadHandle = UAssetManager::GetStreamableManager().RequestAsyncLoad( |
| 292 | This->RequiredAssets->Array(), [CtxHandle]() |
| 293 | { |
| 294 | if (FPCGExContext* NestedThis = GetContextFromHandle<FPCGExContext>(CtxHandle)) { NestedThis->UnpauseContext(); } |
| 295 | }); |
| 296 | |
| 297 | if (!This->LoadHandle || !This->LoadHandle->IsActive()) |
no test coverage detected