Edit 19/03/2019: Completed first revision pass with 's answers
Added time stamps to the 3rd Action video in the comments. After rewatching the Action System set of videos, here are the notes I made, in case anyone finds it useful. I like having huge docs and Ctrl+Fing around when I feel like I need refreshing on certain topics. When thereās a wiki I can start filling some of those entries with this if you wish . If anyone finds anything wrong, youāre more than welcome to correct me guys; Iād love the knowledge. I will update this post with any corrected info.
I will also take this opportunity to ask you more Qs , on what these videos talked.
Event MoveToIndex
-Is generally called from Movement Abilities.
-Will simulate unit movement behind-the-scenes and then queue an action to animate this.
Outputs:
-
IndexPathEnd is the destination index where the unit wants to move to.
-
PathsMap is the output of a pathfinding function.
Function SimulateMove
This function primarily moves the unit reference between GridUnits indices and checks for any events that happen along the way. This includes adding and re-adding units to multiple tiles for big units and calling an event dispatcher every tile move.
Outputs:
-
NewActionsCount: Keeps track of any actions that happen during movement. This can be useful if new actions are called during movement. For instance, if you want to have the unit trigger an explosive half way through its movement you cannot have the whole move action play out and then play the explosion at the end, or the other way around. With this variable you have a way of knowing that new actions have been added to the queue.
Macro QueueAction
Outputs:
-
Immediate Action: Decides whether the action should be executed and animated immediately, or stacked at the bottom of the action queue if set to false. Most actions have this boolean set to false.
-
Executing Object: Defines the object that should execute the action.
-
Action name: All actions have one. These are used to let other functions identify specific actions and decide how to act accordingly.
-
Instant Deactivate: Decides whether the action is instantly considered as āDoneā by the Action Manager as soon as it starts and if itās okay for the next action to roll out. Usually set to false for actions that are to be animated, since normally animations would play out first and then let the game continue.
-
At Custom Index: Specifies a custom order in the queue for the action. For movement, where queuing the movement action is called after SimulateMove (where other actions might be called), but you want movement to start before these actions trigger, this is handy.
-
With Previous: Decides whether this action should be played simultaneously with the one before it.
-
Activation Delay: How much time should be waited until this new action is activated, from the moment the previous action ended.
Event AnimateAction
-This event is generally called from the Action Manager. When an action that needs to be animated comes to the top of the Queue, a signal is sent to the Executing Object (defined in the QueueAction macro) to execute this event.
-This event is contained within BPI Action. Therefore, every BP that should be animated by the action system should have this BPI added.
-This event is multicast, meaning it is run on every client and should automatically work for displaying correctly in Multiplayer.
*-*In order to prevent logic errors and player cheating, it is a good practice to not include any Grid Manager-centered functions in the BP Units, like pathfinding math. If a unit is killed, for instance, it is instantly removed from the GridUnits TMap. If you then try to access this index during the action where it is killed, it has already been removed, causing the code to fail. If you only work with variables that represent the āphysicalā game world, such as locations, actors etc. you can be sure you never have this sort of mismatch. Also, since game logic stuff, such as most of the grid manager stuff, is not replicated, accessing these variables will fail for clients in multiplayer.
Event AnimateMovement
-Units move through a set of spline points that are generated by the Set Spline Points function, which does so using the given path locations.
Action Manager
Event(s) Multicast & InitializeQueuedActions:
-These events are called periodically throughout the game, generally at the end of the unitās turn.
-It empties the temporal array filled by QueueAction macros, sending it to all clients and appending it to the CurrentActions array. After this, each client then starts the first action and plays through them in turn.
-There are two events because the first part of the event (which sorts through actions and stores them in lists) only works server-side, so no need to call it client-side.
Event Dispatcher onUnitEndMovementSimulate
-An event dispatcher that activates when any unit ends its movement during simulation. It is called at the end of the unitās movement, the Simulate Move function.
Other questions:
8-(Video 3/3; 14:45) You use GetActorLocation to obtain the Teleporterās coordinates, and later on (18:40) the Grid Managerās Grid Locations map, to obtain the grid indexā center point. Isnāt it faster and simpler to use the Grid Managerās ConvertIndexToLocation function for this?
: Finding locations in a map uses UE4ās built-in C++ functions and is really fast. Certainly faster than my blueprint function.
9-(Video 3/3; 16:47) Why are only Copies available for the array elements of BP Units, and not References too, like with a vector or integer array?
: This is a C++ thing. For some types of variables it is preferable to create a copy in memory instead of pointing directly to its memory address. Epic have chosen to only allow passing variables referencing blueprints as copies. This is not something you can change in blueprints, but it will generally not matter.
10-Grid Units is a Map array inside Grid Manager. It contains only the grid indices of units. This includes dead units too, right?
: No, they are removed from this array immediately on death. To the grid manager game logic a dead unit means a unit that is neither in the GridUnits TMap or the InitiativeOrder array. If a unit was kept in GridUnits after death, AI units would still try to target them with abilities, and units would not be able to move into the tile they died, for instance.