I am running this each time a vertex snap / editor action occrs
void DoSnap()
{
const FScopedTransaction Transaction( TEXT("Snap"), LOCTEXT( "VictoryEditor", "Vertex Snap" ), VictoryEngine->VSelectedActor );
VictoryEngine->VSelectedActor->Modify();
//I then do the vertex snap here, and end the local context / scope
VictoryEngine->VSelectedActor->SetActorLocation(...);
}
…
And that’s all I know so far!
The issue I have is that sometimes the above works, but others time the chain of undo/redo is broken,
Are there additional steps to play nice with the existing undo/redo system?
You seem to have gotten the majority of it worked out, my guess is that your issue is that every object that has properties modified as part of the transaction needs to have modify called on it. In the case of SetActorLocation that means that properties will be set on the RootComponent and there isn’t an internal Modify call made on the component (possibly questionable that there isn’t, but it is what it is), so you need to do one yourself.
It’s also worth noting that transactions are only saved when the outermost transaction is closed.
That means if you open a scoped transaction in FuncA and call FuncB that also opens a scoped transaction, you won’t see the transaction from FuncB as a separate undo, as it will be merged into the undo opened for FuncA.
I dont know how long it would have taken me to figure that out on my own
My Vertex Snap Editor Plugin now fully supports the UE4 Undo system, thanks to you!
#Plugin Link With Entire Source Code
#Thank You Jamie!
And thank you Jamie for being so prompt in answering my questions !
#Code Sample for Others
#.cpp
#include "ScopedTransaction.h"
#define LOCTEXT_NAMESPACE "VictoryVertexSnapEditor"
//Save an Undo, must target the components directly
//this is after a SetActorLocation() has occurred
//TheActor->SetActorLocation();
const FScopedTransaction Transaction( TEXT("Snap"), LOCTEXT( "VictoryGame", "Victory Vertex Snap" ), TheActor->GetRootComponent() );
TheActor->GetRootComponent()->Modify();
For other folks, now-a-days (4.10) the preferred method is to use the 2 parameter constructor version for FScopedTransaction (second param has default value and isn’t required) rather than the 4 param version e.g.: