Skip to content

Commit

Permalink
Replace hardcoded EAlsLocomotionAction enum with Als.LocomotionAction…
Browse files Browse the repository at this point in the history
… gameplay tags

Add a custom "Blend Poses by Gameplay Tag" animation graph node
  • Loading branch information
Sixze committed Dec 5, 2021
1 parent 8d72381 commit 190a4be
Show file tree
Hide file tree
Showing 46 changed files with 295 additions and 154 deletions.
Binary file modified Content/ALS/Animations/Actions/GetUp/AM_Als_GetUp_Back.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Content/ALS/Animations/Actions/GetUp/AM_Als_GetUp_Front.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Content/ALS/Animations/Actions/Mantle/AM_Als_Mantle_High.uasset
Binary file not shown.
Binary file modified Content/ALS/Animations/Actions/Mantle/AM_Als_Mantle_Low.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Content/ALS/Animations/Actions/Roll/AM_Als_Roll.uasset
Binary file not shown.
Binary file modified Content/ALS/Animations/Actions/Roll/AM_Als_Roll_BothArms.uasset
Binary file not shown.
Binary file modified Content/ALS/Animations/Actions/Roll/AM_Als_Roll_LeftArm.uasset
Binary file not shown.
Binary file modified Content/ALS/Animations/Actions/Roll/AM_Als_Roll_RightArm.uasset
Binary file not shown.
Binary file modified Content/ALS/Character/ABP_Als.uasset
Binary file not shown.
Binary file modified Content/ALS/Character/BP_Als_Character.uasset
Binary file not shown.
Binary file modified Content/ALSCamera/ABP_Als_Camera.uasset
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/ALS/ALS.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public ALS(ReadOnlyTargetRules Target) : base(Target)

PublicDependencyModuleNames.AddRange(new[]
{
"Core", "CoreUObject", "NetCore", "Engine", "PhysicsCore", "GameplayTags", "ControlRig", "Niagara"
"Core", "CoreUObject", "NetCore", "Engine", "PhysicsCore", "GameplayTags", "AnimGraphRuntime", "ControlRig", "Niagara"
});

PrivateDependencyModuleNames.AddRange(new[]
Expand Down
12 changes: 7 additions & 5 deletions Source/ALS/Private/AlsAnimationInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Utility/AlsConstants.h"
#include "Utility/AlsMath.h"
#include "Utility/AlsUtility.h"
#include "Utility/GameplayTags/AlsLocomotionActionTags.h"

UAlsAnimationInstance::UAlsAnimationInstance()
{
Expand Down Expand Up @@ -49,15 +50,16 @@ void UAlsAnimationInstance::NativeUpdateAnimation(const float DeltaTime)
LocomotionMode = AlsCharacter->GetLocomotionMode();
LocomotionAction = AlsCharacter->GetLocomotionAction();

if (PreviousLocomotionAction.IsRagdolling() && !LocomotionAction.IsRagdolling())
if (PreviousLocomotionAction == FAlsLocomotionActionTags::Get().Ragdolling &&
LocomotionAction != FAlsLocomotionActionTags::Get().Ragdolling)
{
StopRagdolling();
}

RefreshLocomotion(DeltaTime);
RefreshLayering();
RefreshView(DeltaTime);

RefreshFeet(DeltaTime);

RefreshMovement(DeltaTime);
Expand Down Expand Up @@ -210,7 +212,7 @@ void UAlsAnimationInstance::RefreshView(const float DeltaTime)
{
ViewState.Rotation = AlsCharacter->GetViewState().SmoothRotation;

if (LocomotionAction.IsNone())
if (!LocomotionAction.IsValid())
{
ViewState.YawAngle = FRotator::NormalizeAxis(ViewState.Rotation.Yaw - AlsCharacter->GetLocomotionState().Rotation.Yaw);
ViewState.PitchAngle = FRotator::NormalizeAxis(ViewState.Rotation.Pitch - AlsCharacter->GetLocomotionState().Rotation.Pitch);
Expand Down Expand Up @@ -308,7 +310,7 @@ void UAlsAnimationInstance::RefreshFeet(const float DeltaTime)
return;
}

if (LocomotionAction.IsRagdolling())
if (LocomotionAction == FAlsLocomotionActionTags::Get().Ragdolling)
{
return;
}
Expand Down Expand Up @@ -1080,7 +1082,7 @@ FAlsLeanState UAlsAnimationInstance::CalculateInAirLeanAmount() const

void UAlsAnimationInstance::RefreshRagdolling()
{
if (LocomotionAction != EAlsLocomotionAction::Ragdolling)
if (LocomotionAction != FAlsLocomotionActionTags::Get().Ragdolling)
{
return;
}
Expand Down
36 changes: 18 additions & 18 deletions Source/ALS/Private/AlsCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Utility/AlsConstants.h"
#include "Utility/AlsLog.h"
#include "Utility/AlsMath.h"
#include "Utility/GameplayTags/AlsLocomotionActionTags.h"

AAlsCharacter::AAlsCharacter(const FObjectInitializer& ObjectInitializer) : Super(
ObjectInitializer.SetDefaultSubobjectClass<UAlsCharacterMovementComponent>(CharacterMovementComponentName))
Expand Down Expand Up @@ -160,8 +161,7 @@ void AAlsCharacter::AddMovementInput(const FVector Direction, const float Scale,
void AAlsCharacter::Jump()
{
if (LocomotionMode == EAlsLocomotionMode::Grounded &&
LocomotionAction == EAlsLocomotionAction::None &&
Stance == EAlsStance::Standing)
!LocomotionAction.IsValid() && Stance == EAlsStance::Standing)
{
Super::Jump();
}
Expand Down Expand Up @@ -195,7 +195,7 @@ void AAlsCharacter::OnStartCrouch(const float HalfHeightAdjust, const float Scal
{
Super::OnStartCrouch(HalfHeightAdjust, ScaledHalfHeightAdjust);

if (LocomotionAction == EAlsLocomotionAction::Rolling)
if (LocomotionAction == FAlsLocomotionActionTags::Get().Rolling)
{
SetStance(DesiredStance); // Keep desired stance when rolling.
return;
Expand Down Expand Up @@ -265,7 +265,7 @@ void AAlsCharacter::ServerSetDesiredStance_Implementation(const EAlsStance NewSt

void AAlsCharacter::ApplyDesiredStance()
{
if (LocomotionAction == EAlsLocomotionAction::None)
if (!LocomotionAction.IsValid())
{
if (LocomotionMode == EAlsLocomotionMode::Grounded)
{
Expand All @@ -285,7 +285,7 @@ void AAlsCharacter::ApplyDesiredStance()
UnCrouch();
}
}
else if (LocomotionAction == EAlsLocomotionAction::Rolling && RollingSettings.bCrouchOnStart)
else if (LocomotionAction == FAlsLocomotionActionTags::Get().Rolling && RollingSettings.bCrouchOnStart)
{
Crouch();
}
Expand Down Expand Up @@ -575,17 +575,17 @@ void AAlsCharacter::SetOverlayMode(const FGameplayTag& NewModeTag)
}
}

void AAlsCharacter::ServerSetOverlayMode_Implementation(const FGameplayTag& NewMode)
void AAlsCharacter::ServerSetOverlayMode_Implementation(const FGameplayTag& NewModeTag)
{
SetOverlayMode(NewMode);
SetOverlayMode(NewModeTag);
}

void AAlsCharacter::OnReplicate_OverlayMode(const FGameplayTag& PreviousModeTag)
{
OnOverlayModeChanged(PreviousModeTag);
}

void AAlsCharacter::OnOverlayModeChanged_Implementation(const FGameplayTag& PreviousMode) {}
void AAlsCharacter::OnOverlayModeChanged_Implementation(const FGameplayTag& PreviousModeTag) {}

void AAlsCharacter::SetLocomotionMode(const EAlsLocomotionMode NewMode)
{
Expand Down Expand Up @@ -615,7 +615,7 @@ void AAlsCharacter::NotifyLocomotionModeChanged(const EAlsLocomotionMode Previou
break;

case EAlsLocomotionMode::InAir:
if (LocomotionAction == EAlsLocomotionAction::None)
if (!LocomotionAction.IsValid())
{
// If the character enters the air, set the in air rotation.

Expand All @@ -631,7 +631,7 @@ void AAlsCharacter::NotifyLocomotionModeChanged(const EAlsLocomotionMode Previou
}
}
}
else if (LocomotionAction == EAlsLocomotionAction::Rolling && RollingSettings.bInterruptRollingWhenInAir)
else if (LocomotionAction == FAlsLocomotionActionTags::Get().Rolling && RollingSettings.bInterruptRollingWhenInAir)
{
// If the character is currently rolling, enable the ragdolling.

Expand All @@ -645,26 +645,26 @@ void AAlsCharacter::NotifyLocomotionModeChanged(const EAlsLocomotionMode Previou

void AAlsCharacter::OnLocomotionModeChanged_Implementation(EAlsLocomotionMode PreviousMode) {}

void AAlsCharacter::SetLocomotionAction(const EAlsLocomotionAction NewAction)
void AAlsCharacter::SetLocomotionAction(const FGameplayTag& NewActionTag)
{
if (LocomotionAction != NewAction)
if (LocomotionAction != NewActionTag)
{
const auto PreviousAction{LocomotionAction};

LocomotionAction = NewAction;
LocomotionAction = NewActionTag;

NotifyLocomotionActionChanged(PreviousAction);
}
}

void AAlsCharacter::NotifyLocomotionActionChanged(const EAlsLocomotionAction PreviousAction)
void AAlsCharacter::NotifyLocomotionActionChanged(const FGameplayTag& PreviousActionTag)
{
ApplyDesiredStance();

OnLocomotionActionChanged(PreviousAction);
OnLocomotionActionChanged(PreviousActionTag);
}

void AAlsCharacter::OnLocomotionActionChanged_Implementation(EAlsLocomotionAction PreviousAction) {}
void AAlsCharacter::OnLocomotionActionChanged_Implementation(const FGameplayTag& PreviousActionTag) {}

void AAlsCharacter::SetInputDirection(FVector NewInputDirection)
{
Expand Down Expand Up @@ -805,7 +805,7 @@ void AAlsCharacter::RefreshView(const float DeltaTime)
void AAlsCharacter::RefreshGroundedActorRotation(const float DeltaTime)
{
if (LocomotionState.bRotationLocked || LocomotionMode != EAlsLocomotionMode::Grounded ||
LocomotionAction != EAlsLocomotionAction::None || HasAnyRootMotion())
LocomotionAction.IsValid() || HasAnyRootMotion())
{
return;
}
Expand Down Expand Up @@ -933,7 +933,7 @@ float AAlsCharacter::CalculateActorRotationSpeed() const
void AAlsCharacter::RefreshInAirActorRotation(const float DeltaTime)
{
if (LocomotionState.bRotationLocked || LocomotionMode != EAlsLocomotionMode::InAir ||
LocomotionAction != EAlsLocomotionAction::None || TryRefreshCustomInAirActorRotation(DeltaTime))
LocomotionAction.IsValid() || TryRefreshCustomInAirActorRotation(DeltaTime))
{
return;
}
Expand Down
26 changes: 14 additions & 12 deletions Source/ALS/Private/AlsCharacter_Actions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "AlsCharacter.h"

#include "AlsCharacterMovementComponent.h"
#include "DrawDebugHelpers.h"
#include "Animation/AnimInstance.h"
Expand All @@ -12,6 +13,7 @@
#include "Utility/AlsConstants.h"
#include "Utility/AlsMath.h"
#include "Utility/AlsUtility.h"
#include "Utility/GameplayTags/AlsLocomotionActionTags.h"

bool AAlsCharacter::TryStartMantlingGrounded()
{
Expand All @@ -27,7 +29,7 @@ bool AAlsCharacter::TryStartMantlingInAir()

bool AAlsCharacter::IsMantlingAllowedToStart() const
{
return LocomotionAction == EAlsLocomotionAction::None;
return !LocomotionAction.IsValid();
}

bool AAlsCharacter::TryStartMantling(const FAlsMantlingTraceSettings& TraceSettings)
Expand Down Expand Up @@ -358,7 +360,7 @@ void AAlsCharacter::StartMantlingImplementation(const FAlsMantlingParameters& Pa
EMontagePlayReturnType::MontageLength,
MontageStartTime, false))
{
SetLocomotionAction(EAlsLocomotionAction::Mantling);
SetLocomotionAction(FAlsLocomotionActionTags::Get().Mantling);
}
}

Expand Down Expand Up @@ -425,7 +427,7 @@ void AAlsCharacter::OnMantlingEnded_Implementation() {}

bool AAlsCharacter::IsRagdollingAllowedToStart() const
{
return LocomotionAction != EAlsLocomotionAction::Ragdolling;
return LocomotionAction != FAlsLocomotionActionTags::Get().Ragdolling;
}

void AAlsCharacter::StartRagdolling()
Expand Down Expand Up @@ -482,7 +484,7 @@ void AAlsCharacter::StartRagdollingImplementation()
GetCharacterMovement()->SetMovementMode(MOVE_None);
AlsCharacterMovement->SetMovementModeLocked(true);

SetLocomotionAction(EAlsLocomotionAction::Ragdolling);
SetLocomotionAction(FAlsLocomotionActionTags::Get().Ragdolling);

// Disable capsule collision and enable mesh physics simulation starting from the pelvis.

Expand Down Expand Up @@ -526,7 +528,7 @@ void AAlsCharacter::ServerSetRagdollTargetLocation_Implementation(const FVector&

void AAlsCharacter::RefreshRagdolling(const float DeltaTime)
{
if (LocomotionAction != EAlsLocomotionAction::Ragdolling)
if (LocomotionAction != FAlsLocomotionActionTags::Get().Ragdolling)
{
return;
}
Expand Down Expand Up @@ -625,7 +627,7 @@ void AAlsCharacter::RefreshRagdollingActorTransform(const float DeltaTime)

bool AAlsCharacter::IsRagdollingAllowedToStop() const
{
return LocomotionAction == EAlsLocomotionAction::Ragdolling;
return LocomotionAction == FAlsLocomotionActionTags::Get().Ragdolling;
}

bool AAlsCharacter::TryStopRagdolling()
Expand Down Expand Up @@ -676,7 +678,7 @@ void AAlsCharacter::StopRagdollingImplementation()

GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);

SetLocomotionAction(EAlsLocomotionAction::None);
SetLocomotionAction(FGameplayTag::EmptyTag);

// If the ragdoll is on the ground, set the movement mode to walking and play a get up animation. If not, set
// the movement mode to falling and update the character movement velocity to match the last ragdoll velocity.
Expand Down Expand Up @@ -704,7 +706,7 @@ void AAlsCharacter::StopRagdollingImplementation()
GetMesh()->GetAnimInstance()->Montage_Play(SelectGetUpMontage(RagdollingState.bFacedUpward), 1.0f,
EMontagePlayReturnType::MontageLength, 0.0f, true))
{
SetLocomotionAction(EAlsLocomotionAction::GettingUp);
SetLocomotionAction(FAlsLocomotionActionTags::Get().GettingUp);
}
}

Expand All @@ -731,9 +733,9 @@ void AAlsCharacter::TryStartRolling(const float PlayRate)

bool AAlsCharacter::IsRollingAllowedToStart(const UAnimMontage* Montage) const
{
return LocomotionAction == EAlsLocomotionAction::None ||
return !LocomotionAction.IsValid() ||
// ReSharper disable once CppRedundantParentheses
(LocomotionAction == EAlsLocomotionAction::Rolling &&
(LocomotionAction == FAlsLocomotionActionTags::Get().Rolling &&
!GetMesh()->GetAnimInstance()->Montage_IsPlaying(Montage));
}

Expand Down Expand Up @@ -800,13 +802,13 @@ void AAlsCharacter::StartRollingImplementation(UAnimMontage* Montage, const floa

if (GetMesh()->GetAnimInstance()->Montage_Play(Montage, PlayRate))
{
SetLocomotionAction(EAlsLocomotionAction::Rolling);
SetLocomotionAction(FAlsLocomotionActionTags::Get().Rolling);
}
}

void AAlsCharacter::RefreshRolling(const float DeltaTime)
{
if (LocomotionState.bRotationLocked || LocomotionAction != EAlsLocomotionAction::Rolling)
if (LocomotionState.bRotationLocked || LocomotionAction != FAlsLocomotionActionTags::Get().Rolling)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/ALS/Private/AlsCharacter_Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void AAlsCharacter::DisplayDebugState(const UCanvas* Canvas, const float Scale,
Text.Text = LocomotionActionText;
Text.Draw(Canvas->Canvas, {HorizontalPosition, VerticalPosition});

Text.Text = FText::AsCultureInvariant(FName::NameToDisplayString(GetEnumValueString(LocomotionAction), false));
Text.Text = FText::AsCultureInvariant(FName::NameToDisplayString(UAlsUtility::GetSimpleTagName(LocomotionAction).ToString(), false));
Text.Draw(Canvas->Canvas, {HorizontalPosition + ColumnOffset, VerticalPosition});

VerticalPosition += RowOffset;
Expand Down
32 changes: 32 additions & 0 deletions Source/ALS/Private/Node/AlsAnimNode_GameplayTagsBlend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "Node/AlsAnimNode_GameplayTagsBlend.h"

int32 FAlsAnimNode_GameplayTagsBlend::GetActiveChildIndex()
{
return ActiveTag.IsValid()
? Tags.Find(ActiveTag) + 1
: 0;
}

void FAlsAnimNode_GameplayTagsBlend::RefreshPoses()
{
const auto Difference{BlendPose.Num() - Tags.Num() - 1};
if (Difference == 0)
{
return;
}

if (Difference > 0)
{
for (auto i{Difference}; i > 0; i--)
{
RemovePose(BlendPose.Num() - 1);
}
}
else
{
for (auto i{Difference}; i < 0; i++)
{
AddPose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

#include "AlsCharacter.h"
#include "Components/SkeletalMeshComponent.h"
#include "State/Enumerations/AlsLocomotionAction.h"
#include "Utility/AlsEnumerationUtility.h"
#include "Utility/AlsUtility.h"

UAlsAnimNotifyState_SetLocomotionAction::UAlsAnimNotifyState_SetLocomotionAction()
{
Expand All @@ -12,7 +11,9 @@ UAlsAnimNotifyState_SetLocomotionAction::UAlsAnimNotifyState_SetLocomotionAction

FString UAlsAnimNotifyState_SetLocomotionAction::GetNotifyName_Implementation() const
{
return FString::Format(TEXT("Als Set Locomotion Action: {0}"), {GetEnumValueString(Action)});
return FString::Format(TEXT("Als Set Locomotion Action: {0}"), {
FName::NameToDisplayString(UAlsUtility::GetSimpleTagName(LocomotionAction).ToString(), false)
});
}

void UAlsAnimNotifyState_SetLocomotionAction::NotifyBegin(USkeletalMeshComponent* MeshComponent, UAnimSequenceBase* Animation,
Expand All @@ -23,7 +24,7 @@ void UAlsAnimNotifyState_SetLocomotionAction::NotifyBegin(USkeletalMeshComponent
auto* Character{Cast<AAlsCharacter>(MeshComponent->GetOwner())};
if (IsValid(Character))
{
Character->SetLocomotionAction(Action);
Character->SetLocomotionAction(LocomotionAction);
}
}

Expand All @@ -32,8 +33,8 @@ void UAlsAnimNotifyState_SetLocomotionAction::NotifyEnd(USkeletalMeshComponent*
Super::NotifyEnd(MeshComponent, Animation);

auto* Character{Cast<AAlsCharacter>(MeshComponent->GetOwner())};
if (IsValid(Character) && Character->GetLocomotionAction() == Action)
if (IsValid(Character) && Character->GetLocomotionAction() == LocomotionAction)
{
Character->SetLocomotionAction(EAlsLocomotionAction::None);
Character->SetLocomotionAction(FGameplayTag::EmptyTag);
}
}

0 comments on commit 190a4be

Please sign in to comment.