You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-7Lines changed: 8 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
1
# CommandPlugin
2
2
Command Pattern for implementing undo/redo systems in Unreal Engine.
3
3
4
-
5
4
### Command Pattern?
6
5
7
6
The basic idea behind using the command pattern for undo / redo is to wrap any function that needs to be undoable with a command.
@@ -13,7 +12,6 @@ For more information on the command pattern see: [refactoring guru - command pat
13
12
Note: This Unreal Engine implementation uses "Do" instead of "Execute".
14
13
This change was made to avoid confusion when calling [UINTERFACE](https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/GameplayArchitecture/Interfaces/) functions in C++, which use a generated Execute_ function: ICommand::Execute_Do();
15
14
16
-
17
15
### Guidelines
18
16
19
17
Hard-ish rules to be aware of. Be careful if your use case needs to break one.
@@ -34,6 +32,7 @@ This message should reflect the new value, which is set by calling `ICommand.Do(
34
32
### Function -> ICommand
35
33
36
34
Here is an example of how to turn a function into a command:
35
+
Let's start with an example object `ExampleState` with a function `SetX()` that we want to track in the command history.
37
36
38
37
```
39
38
class ExampleState
@@ -46,11 +45,11 @@ public:
46
45
}
47
46
```
48
47
49
-
In order to call `SetX()` we will need:
48
+
In order to call `SetX()`from a command we will need:
50
49
1) a reference to the object it's being called on
51
50
2) the float value we want to use
52
51
53
-
These will be assigned in the costructor (or exposed on spawn in blueprint)
52
+
These will be assigned in the costructor of our command (exposed on spawn in blueprint)
54
53
55
54
```
56
55
class ExampleCommand : pubic ICommand
@@ -66,9 +65,11 @@ class ExampleCommand : pubic ICommand
FString GetDisplayString_Implementation() overrid { return "updated X on target"; }
72
71
}
73
72
```
74
73
74
+
Notice that `OldX` does not need to be passed in to the constructor. Since there is already have a reference to the state object, we can simply call `GetX()` to cache the current state.
0 commit comments