Memento Service
A robust state management system for Unity that provides undo/redo functionality with flexible service levels
In One Line
State historians unite: Yesterday's code is just an undo away!
Overview
Memento Service implements the Memento pattern to manage state history, offering both local and background service modes. It's perfect for implementing undo/redo systems in editors, game states, or any scenario requiring state history management.
The Memento Service seamlessly integrates with both Unity Components and regular C# classes.
Package Info
display name
AceLand Menento Service
package name
latest version
1.0.11
namespace
git repository
dependencies
Key Features
Two service modes: Global & Local
Generic type support for any state type
Configurable history limit
Automatic resource cleanup on Global Service
Project Settings
Settings
---
Memento Service Mode
Select service supporting follow modes:
Local OnlyGlobal and Local
default: Global and Local
Undo Limit
How many Undo record can be storaged in Memento per service.
mininum: 4 default: 32
Log Level
Level of Logging
default: BuildLevel.DevelopmentBuild
Global Service Mode
By Calling Memento API to use the global service.
Global Service save only data inherited GlobalMementoState. See Advance Global Use for details.
Create a Global Memento State
Use the Global Memento Service
Local Service Mode
By building Memento Service to use the local service.
This mode is object-specific recommended for save memento state by object.
Create a Local Memento State as ref type
Create a Local Memento State as data struct type
Create your Local Memento Service
Use the Service
When building a Local Service, default History Limit can be set in Project Setting.
In case of specified history limit:
minimun History Limit is 4
it cannot be changed after service built
State History Behavior
Undo/Redo Stack Management
Undo/Redo Operations
Neither undo nor redo operations destroy state history
States remain in memory for potential future use
Switching between states preserves the full history
Adding New States
Saving a new state clears all redo history
Best Practices
Memory Management
State Design
Service Selection
Use Global Service for customized GlobalMementoState
Use Local Service for object-specific or component-specific states
Consider memory implications with large state histories
Usage in Unity
The workflow is the same. Here is an example to use Local Memento Service to record a Transform state.
Create a Local Memento State for Transform
Create a MonoBehaviour component with Local Memento Service
Advance Local Use
Example is using above TransformState.
Create a class with Memento Service to make a state-controlable object.
Create a MonoBehaviour Component with the TransformStateMemento.
Advance Global Use
Here is an example to make a Transfrom Memento State for global service.
Create a Global Memento State for Transform
Create a Global Memento component to save the state.
Create a Global Memento Events component to Undo, Redo and Clear History.
With AceLand.Input events, set hotkeys to Undo and Redo in a second.
Simple Global Test
Test with above Transform Memento State with Inspector Buttons.
Technical Notes
History limit is enforced to prevent memory issues
Thread-safe operations for background service
Automatic cleanup of disposed states
Generic type support enables type-safe operations
Do not Save GameObject and Component to service
Last updated