All non-combat animations for NPCs should be handled by the Emote Controller. The Emote Controller is already integrated into many other systems, animation blueprints, character states, and so on. Playing montages directly could create many problems, like NPCs moving and playing emote at the same time.
Emotes can be used in 4 different ways, with the following priority:
The PlayEmote async node
Directly setting the value of IdleEmote Int Stat
Setting Emote State in owning ManualSpawnPoint
Directly calling Start Emote on Emote Controller
The PlayEmote async node will try to start to emote on the target character once. This behavior is controlled from the BT_Passive behavior tree:
Looping emotes will be played for the duration specified by the Timeout parameter of the PlayEmote async node, or until they are directly stopped (by calling StopEmote), interrupted, or changed to another emote.
After the emote is finished/stopped/interrupted, the NPC will go back to its normal behavior.
The PlayEmote node can affect the behavior of NPCs while emoting:
CanBeDamaged - If false, the target character will be invulnerable for all attacks, including Knockback while playing target emote.
CanEnterKnockback - If false, target will ignore Knockback damage while playing target emote. Knockback damage can be applied only if canBeDamaged is set to true. Please note that entering knockback can interrupt playing emote.
CanBeTargeted - If false, the target character will be ignored by other NPCs while playing target emote.
ShouldEngageInCombat - If false, the target character will not engage in combat while playing target emote, even if attacked. Please note that engaging in combat will force NPC to stop playing the current emote.
ShouldContinueMovement – If false, the target character will stop any movement before playing emote. Otherwise, NPC will continue the ongoing movement and play emote at the same time.
Timeout - How long the target character is allowed to play given emote, especially useful for looping emotes with flag WillLoopUntilCanceled. If Duration <= 0, emote will play until its end, or loop indefinitely in the case of looping emotes.
Please note that the PlayEmote async node is temporarily using IdleEmote Int Stat to store the currently played emote. After the emote is finished, the value of IdleEmote Int Stat will be reverted to the previous value.
The non-roaming NPCs can play idle emote if they are at their home locations and if they are not engaged in combat. This behavior is controlled from the BT_Passive behavior tree:
The idle emote can be set in two ways, directly setting the value of IdleEmote Int Stat or by Setting Emote State in owning ManualSpawnPoint.
The IdleEmote Int Stat can be set for any NPC, independent of the spawning method.
Emote set up in the IdleEmote Int Stat will be prioritized over the Emote State in owning ManualSpawnPoint.
Idle emote can be also set automatically for NPCs spawned from the BP_ManualSpawnPoint.
NPCs using Idle Emote from the owner BP_ManualSpawnPoint will use the same rotation as the owner BP_ManualSpawnPoint. This could be used to rotate emote NPCs in the desired direction, which may be useful for some emotes.
This method is not recommended and was used before we added the PlayEmote async node, which provides the same functionality, but also automatically prepares the NPCs for emoting, integrates emoting with behavior tree and automatically reverts the NPCs exactly to the state before emote. Calling Start Emote directly on Emote Controller does not guarantee that the emote will not be interrupted or blocked by other actions.
Emotes can be also started directly by calling the Start Emote function on Emote Controller of given NPC.
Emotes are already used in that way in theBP_BaseBossControllers (node StartBossEmote), usually in after “blinding” NPCs to prevent them from attacking player
New emotes can be added to the EmotesDataTable (/Game/Characters/Emotes/EmotesDataTable).
Each row in that table represent emote (that can be identified by EmoteID) available for characters using the same Skeleton (column CompatibleSkeleton), e.g. to add new emote for both humanoids (using SK_human_Skeleton) and crocodiles (using SK_crocodile_Skeleton) we need to add two new rows with the same EmoteID, but having different CompatibleSkeleton.
Please note that there can be only one emote using given EmoteID per Skeleton. If there is more than one emote with the same EmoteID and the same CompatibleSkeleton, only the first one in the table will be ever used.
Available EmotedIDs are based on the ECharacterEmotes enum, that can be extended only from Code (EmoteTableRow.h).
Other columns in the EmotesDataTable are:
EmoteID - enum use to identify given emote. Each EmoteID can be used only once per skeleton
Name - name of the emote, that will be visible to players in the emote radial menu
EmoteFlags - specifies additional properties of the emote:
BlockMovement - prevents the player character from movement while emote is playing. Please note that this flag is not affecting NPCs , as their movement is controlled by behavior tree.
WillLoopUntilCanceled - This flag assumes that montage for this emote has internal loop and EmoteEnd section. Internal loop will prevent emote from finishing by itself, but if the emote is directly stopped (by calling StopEmote), interrupted, or changed to another emote it will first jump to the the EmoteEnd section of the montage. Please note that this flag by itself will not cause emote to loop!
CantEquipItems - prevents players from using items while emote is playing. It affects also using item in the ShortcutBar, and fighting.
NPCShouldHaveWeapons - NPCs will equip their weapons before playing this emote (if this flag is set to false characters will always unequip weapons before playing an emote).
IsThrallIdleEmote - marks emotes that can be assigned by players to their followers in the followers emote menu. Please not that players still have to learn that emote to access it in the followers emote menu.
IsNPCOnly - this emote can never be shown to players in the player character emote radial menu, but it can still be used as the NPC emote by us, as well as players in the followers emote menu.
RandomDeviationFromBreakTime - +/- range in which the BreakTime can vary from break to break.
EmoteAnimMontageMale, EmoteAnimMontageFemale - actual montages used for the emote. Female version is used if owner character has UCharacterCustomizationComponent with Layout.BoolParams.IsFemale set to true.
CompatibleSkeleton - column used to match emote row with request EmoteID to actual mesh of target character.
Icon and IconLayers - sets icon visible in the player and follower emote radial menu
EmoteCategory - used to split emotes in categories in the player emote radial menu and the follower emote radial menu. Please note that emotes will be moved into the category submenu only if there is more than one emote from the same category available in the radial menu. Emote categories are set up in the /Game/UI/RadialMenus/EmoteCategoriesTable data table. Available EmoteCategory are based on the EEmoteCategoriesenum, that can be extended only from Code (EmoteTableRow.h).