MothCocoon / FlowGraph

Design-agnostic node system for scripting game’s flow in Unreal Engine
https://discord.gg/Xmtr6GhbmW
MIT License
1.17k stars 228 forks source link

Fix issue https://github.com/MothCocoon/FlowGraph/issues/187 #189

Closed MaksymKapelianovych closed 5 months ago

MaksymKapelianovych commented 5 months ago

The reason of that issue was, that during transactions, resetting pin arrays was not stored as part of the transaction, and after undo/redo action these arrays were empty and pins connections could not be properly restored or removed.

void UFlowGraphNode::ReconstructNode()
{
        ... 
    // Reset pin arrays
    Pins.Reset();
    InputPins.Reset();
    OutputPins.Reset();
         ...
}

To fix this we simply need to call Modify() before changing pins arrays. I decided to add this into the OnExternalChange() function and not into the ReconstructNode() itself, because in other places, where ReconstructNode() is called, transactions (and Modify() function call) exist in calling functions. I did not add transaction object itself, because if the OnExternalChange() is called from property modification event, it is already inside transaction, and if it is called from BP compilation, then this transaction would be stored as a separate transaction, and undoing it would not bring much use (to undo actual changes, user needs to press Ctrl+Z again).

MaksymKapelianovych commented 5 months ago

This issue was reproduced with nodes PlayLevelSequence, CallOwnerFunction, SubGraph (when adding custom input/output), basically every node, that call OnReconstructionRequested.ExecuteIfBound() from its PostEditChangeProperty(). With my fix everything is working properly.

MothDoctor commented 5 months ago

Thank you, it works beautifully! :)