Undo / Redo Transaction Fails

Not sure what I’m doing wrong here. I’m creating a custom module-based editor for a class, and I’m trying to add undo and redo support for adding and removing modules.

Here’s an example of what I’m doing:

Code:

// Create an Undoable Transaction
{
	FScopedTransaction Trans = FScopedTransaction(LOCTEXT("CreateOrdModule_Transaction", "Create Module"));
	CurrentTemplate->Modify();

	// Notify Template
	CurrentTemplate->PreEditChange(nullptr);

	// Construct Module and add to selected emitter
	UST_OrdnanceModule* NewModule = NewObject<UST_OrdnanceModule>(CurrentTemplate, NewModuleClass, NAME_None, RF_Transactional);
	NewModule->Modify();
	NewModule->SetToSensibleDefaults();
	NewModule->SetTransactionFlag();

	CurrentTemplate->OrdnanceModules.Add(NewModule);

	CurrentTemplate->OnModulesUpdated();
	CurrentTemplate->PostEditChange();

	ForceRefresh();
}

But if I call Undo after running this transaction, the module is NOT removed from the array. The Array is a UPROPERTY with no extra meta data.

What am I doing wrong here?

Hi… I know it’s been a while, but I’m trying to understand the Transaction paradigm. Have you gained any extra insight about this topic that you can share? Thanks! :slight_smile: