MCPcopy Create free account
hub / github.com/MothCocoon/FlowGraph / OnGameSaved

Method OnGameSaved

Source/Flow/Private/FlowSubsystem.cpp:367–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365}
366
367void UFlowSubsystem::OnGameSaved(UFlowSaveGame* SaveGame)
368{
369 // clear existing data, in case we received reused SaveGame instance
370 // we only remove data for the current world + global Flow Graph instances (i.e. not bound to any world if created by UGameInstanceSubsystem)
371 // we keep data bound to other worlds
372 if (GetWorld())
373 {
374 const FString& WorldName = GetWorld()->GetName();
375
376 for (int32 i = SaveGame->FlowInstances.Num() - 1; i >= 0; i--)
377 {
378 if (SaveGame->FlowInstances[i].WorldName.IsEmpty() || SaveGame->FlowInstances[i].WorldName == WorldName)
379 {
380 SaveGame->FlowInstances.RemoveAt(i);
381 }
382 }
383
384 for (int32 i = SaveGame->FlowComponents.Num() - 1; i >= 0; i--)
385 {
386 if (SaveGame->FlowComponents[i].WorldName.IsEmpty() || SaveGame->FlowComponents[i].WorldName == WorldName)
387 {
388 SaveGame->FlowComponents.RemoveAt(i);
389 }
390 }
391 }
392
393 // save Flow Graphs
394 for (const TPair<UFlowAsset*, TWeakObjectPtr<UObject>>& RootInstance : ObjectPtrDecay(RootInstances))
395 {
396 if (RootInstance.Key && RootInstance.Value.IsValid())
397 {
398 if (UFlowComponent* FlowComponent = Cast<UFlowComponent>(RootInstance.Value))
399 {
400 FlowComponent->SaveRootFlow(SaveGame->FlowInstances);
401 }
402 else
403 {
404 RootInstance.Key->SaveInstance(SaveGame->FlowInstances);
405 }
406 }
407 }
408
409 // save Flow Components
410 {
411 // retrieve all registered components
412 TArray<TWeakObjectPtr<UFlowComponent>> ComponentsArray;
413 FlowComponentRegistry.GenerateValueArray(ComponentsArray);
414
415 // ensure uniqueness of entries
416 const TSet<TWeakObjectPtr<UFlowComponent>> RegisteredComponents = TSet<TWeakObjectPtr<UFlowComponent>>(ComponentsArray);
417
418 // write archives to SaveGame
419 for (const TWeakObjectPtr<UFlowComponent> RegisteredComponent : RegisteredComponents)
420 {
421 SaveGame->FlowComponents.Emplace(RegisteredComponent->SaveInstance());
422 }
423 }
424}

Callers 1

ExecuteInputMethod · 0.80

Calls 5

IsEmptyMethod · 0.80
IsValidMethod · 0.80
SaveRootFlowMethod · 0.80
GetNameMethod · 0.45
SaveInstanceMethod · 0.45

Tested by

no test coverage detected