Skip to content

Commit

Permalink
Update FlowAsset.cpp (#73)
Browse files Browse the repository at this point in the history
Prevention of auto checkout when instancing flow asset
  • Loading branch information
GameDevGrzesiek authored and MothDoctor committed Nov 17, 2021
1 parent 63cd32e commit c808530
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions Source/Flow/Private/FlowAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void UFlowAsset::UnregisterNode(const FGuid& NodeGuid)
void UFlowAsset::HarvestNodeConnections()
{
TMap<FName, FConnectedPin> Connections;
bool bModified = false;

// last moment to remove invalid nodes
for (auto NodeIt = Nodes.CreateIterator(); NodeIt; ++NodeIt)
Expand All @@ -113,13 +114,15 @@ void UFlowAsset::HarvestNodeConnections()
if (Pair.Value == nullptr)
{
NodeIt.RemoveCurrent();
bModified = true;
}
}

for (const TPair<FGuid, UFlowNode*>& Pair : Nodes)
{
UFlowNode* Node = Pair.Value;
Connections.Empty();
TMap<FName, FConnectedPin> CurrentConnections = Node->Connections;

for (const UEdGraphPin* ThisPin : Node->GetGraphNode()->Pins)
{
Expand All @@ -129,19 +132,39 @@ void UFlowAsset::HarvestNodeConnections()
{
const UEdGraphNode* LinkedNode = LinkedPin->GetOwningNode();
Connections.Add(ThisPin->PinName, FConnectedPin(LinkedNode->NodeGuid, LinkedPin->PinName));

// check if connection already exists
bool bFoundConnection = false;
for (TPair<FName, FConnectedPin>& KeyVal : CurrentConnections)
{
if (KeyVal.Value.NodeGuid == LinkedNode->NodeGuid && KeyVal.Value.PinName == LinkedPin->PinName)
{
bFoundConnection = true;
break;
}
}

// if not - we will have to override connections and modify the asset
if (!bFoundConnection)
{
bModified = true;
}
}
}
}

if (bModified)
{
#if WITH_EDITOR
Node->SetFlags(RF_Transactional);
Node->Modify();
Node->SetFlags(RF_Transactional);
Node->Modify();
#endif
Node->SetConnections(Connections);
Node->SetConnections(Connections);

#if WITH_EDITOR
Node->PostEditChange();
#endif
Node->PostEditChange();
#endif
}
}
}

Expand Down

0 comments on commit c808530

Please sign in to comment.