Undo/Redo System | How to use it correctly?

Hey there,

I’m currently trying to setup my own EditorTools and I would like to combine them with the Undo/Redo system.
From the Stream about EditorExtensions I learned to use this:

FScopedTransaction Transaction(LOCTEXT("RefreshDebugConnectionLines", "Refresh Debug Connection Lines"));
StreetVertexConnectionDebugger->Modify();

I managed to get Spawning and Deleting Actors to be undone by doing this:

GEditor->BeginTransaction(NSLOCTEXT("TrafficPlacementTool", "SpawnNewStreetVertex", "Spawn New StreetVertex"));

// Spawn Code

GEditor->EndTransaction();

But the Editor Crashes if I try to undo the refreshing of DebugLines:

void AStreetVertex::RefreshDebugConnectionLines()
{
	FScopedTransaction Transaction(LOCTEXT("RefreshDebugConnectionLines", "Refresh Debug Connection Lines"));
	StreetVertexConnectionDebugger->Modify();

	// Clear all existing Lines
	StreetVertexConnectionDebugger->Flush();

	// Create a new line from this Vertex to the connected ones
	for (AStreetVertex* ConnectedVertex : ConnectedVectices)
	{
		if (ConnectedVertex)
		{
			StreetVertexConnectionDebugger->DrawLine(GetActorLocation(), ConnectedVertex->GetActorLocation(), FColor::Orange, 0, 5.f);
		}	
	}
}

What am I doing here?

“StreetVertex” Actors are connected to each other by references in the “ConnectedVectices” Array.
So if two StreetVertices (A and B) are connected then StreetVertexA has a Reference of StreetVertexB and other way round.
The connection is show by a DebugLine from A to B and B to A. “StreetVertexConnectionDebugger” is a ULineBatchComponent.

When I spawn an Actor while other StreetVertices are select, it directly adds them to each others Array and then calls “RefreshDebugConnectionLines”. If I delete a Vertex, the line of that Vertex gets removed and it also tells everyone else that the Vertex was removed and they call the Refresh function again.
But when I simply undo the spawning the connected Vertices never get notified so I tried to just save the Transaction so it gets undone.

But when using the code above, the editor crashes on undo:

Any idea how this should be handled?