Skip to content

Commit

Permalink
do not call Start node on Sub Graph loaded from save
Browse files Browse the repository at this point in the history
  • Loading branch information
MothDoctor committed Feb 22, 2022
1 parent d836e91 commit 4cb9ec2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions Source/Flow/Private/FlowSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ void UFlowSubsystem::FinishRootFlow(UObject* Owner, const EFlowFinishPolicy Fini
}
}

UFlowAsset* UFlowSubsystem::CreateSubFlow(UFlowNode_SubGraph* SubGraphNode, const FString NewInstanceName, const bool bPreloading /* = false */)
UFlowAsset* UFlowSubsystem::CreateSubFlow(UFlowNode_SubGraph* SubGraphNode, const FString SavedInstanceName, const bool bPreloading /* = false */)
{
UFlowAsset* NewInstance = nullptr;

if (!InstancedSubFlows.Contains(SubGraphNode))
{
const TWeakObjectPtr<UObject> Owner = SubGraphNode->GetFlowAsset() ? SubGraphNode->GetFlowAsset()->GetOwner() : nullptr;
NewInstance = CreateFlowInstance(Owner, SubGraphNode->Asset, NewInstanceName);
NewInstance = CreateFlowInstance(Owner, SubGraphNode->Asset, SavedInstanceName);
InstancedSubFlows.Add(SubGraphNode, NewInstance);

if (bPreloading)
Expand All @@ -124,8 +124,12 @@ UFlowAsset* UFlowSubsystem::CreateSubFlow(UFlowNode_SubGraph* SubGraphNode, cons

AssetInstance->NodeOwningThisAssetInstance = SubGraphNode;
SubGraphNode->GetFlowAsset()->ActiveSubGraphs.Add(SubGraphNode, AssetInstance);

AssetInstance->StartFlow();

// don't activate Start Node if we're loading Sub Graph from SaveGame
if (SavedInstanceName.IsEmpty())
{
AssetInstance->StartFlow();
}
}

return NewInstance;
Expand Down Expand Up @@ -221,7 +225,7 @@ void UFlowSubsystem::OnGameSaved(UFlowSaveGame* SaveGame)
TArray<TWeakObjectPtr<UFlowComponent>> ComponentsArray;
FlowComponentRegistry.GenerateValueArray(ComponentsArray);
const TSet<TWeakObjectPtr<UFlowComponent>> FlowComponents = TSet<TWeakObjectPtr<UFlowComponent>>(ComponentsArray);
for (TWeakObjectPtr<UFlowComponent> FlowComponent : FlowComponents)
for (const TWeakObjectPtr<UFlowComponent> FlowComponent : FlowComponents)
{
SaveGame->FlowComponents.Emplace(FlowComponent->SaveInstance());
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Flow/Public/FlowSubsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class FLOW_API UFlowSubsystem : public UGameInstanceSubsystem
void FinishRootFlow(UObject* Owner, const EFlowFinishPolicy FinishPolicy);

private:
UFlowAsset* CreateSubFlow(UFlowNode_SubGraph* SubGraphNode, const FString NewInstanceName = FString(), const bool bPreloading = false);
UFlowAsset* CreateSubFlow(UFlowNode_SubGraph* SubGraphNode, const FString SavedInstanceName = FString(), const bool bPreloading = false);
void RemoveSubFlow(UFlowNode_SubGraph* SubGraphNode, const EFlowFinishPolicy FinishPolicy);

UFlowAsset* CreateFlowInstance(const TWeakObjectPtr<UObject> Owner, TSoftObjectPtr<UFlowAsset> FlowAsset, FString NewInstanceName = FString());
Expand Down

0 comments on commit 4cb9ec2

Please sign in to comment.