Skip to content

Commit f6675d6

Browse files
authored
Updated README example for consistent naming
1 parent af7701e commit f6675d6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# CommandPlugin
22
Command Pattern for implementing undo/redo systems in Unreal Engine.
33

4-
54
### Command Pattern?
65

76
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
1312
Note: This Unreal Engine implementation uses "Do" instead of "Execute".
1413
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();
1514

16-
1715
### Guidelines
1816

1917
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(
3432
### Function -> ICommand
3533

3634
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.
3736

3837
```
3938
class ExampleState
@@ -46,11 +45,11 @@ public:
4645
}
4746
```
4847

49-
In order to call `SetX()` we will need:
48+
In order to call `SetX()` from a command we will need:
5049
1) a reference to the object it's being called on
5150
2) the float value we want to use
5251

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)
5453

5554
```
5655
class ExampleCommand : pubic ICommand
@@ -66,9 +65,11 @@ class ExampleCommand : pubic ICommand
6665
OldX = Target->GetX(); // store the old value
6766
}
6867
69-
void Do_Implementation() override { Target->SetX(NewValue); }
70-
void Undo_Implementation() override { Target->SetX(OldValue); }
71-
FString GetDisplayString_Implementation() overrid { return "SetX"; }
68+
void Do_Implementation() override { Target->SetX(NewX); }
69+
void Undo_Implementation() override { Target->SetX(OldX); }
70+
FString GetDisplayString_Implementation() overrid { return "updated X on target"; }
7271
}
7372
```
7473

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.
75+

0 commit comments

Comments
 (0)