The challenge for this end of chapter was to get a 2 handed weapon and attach it to your mesh with an appropriate animation sequence.
Decided rather than using a new weapon for the time being I'd add different styles since I am using a katana. Lots of fun figuring out that my weapon pointer wasn't getting de-referenced, but that pressing a button to fire events goes faster than the engine can handle, and you need to add Pressed to your Input Action Trigger. Echo now can swap between Equipped, 1 Handed, or Two handed styles, but I need to fix the hand placement since the animation didn't quite line up.
I added additional styles to the state enumeration and bound a key to cycle through them. You absolutely cannot use digital bool as the input. There is likely a way to make sure you don't overload the engine with spam pointer dereference calls but the simplest path forward was to set it to respond in the "Pressed" state, not a continuous call to the Input Mapping Context.
My header file:
UENUM(BlueprintType)
enum class ECharacterEquipState : uint8
{
ECS_Sheathed UMETA(DisplayName = "Sheathed"),
ECS_Equipped1H UMETA(DisplayName = "Equipped One Hand"),
ECS_Equipped2H UMETA(DisplayName = "Equipped Two Hand"),
ECS_EquippedAkimbo UMETA(DisplayName = "Equipped Dual Weild"),
ECS_UnEquipped UMETA(DisplayName = "Uequipped"),
ECS_Count UMETA(Hidden),
};
ECharacterEquipState NextState(ECharacterEquipState State);
/*The NextState function: */
ECharacterEquipState NextState(ECharacterEquipState State)
{
const int count = static_cast<int>(ECharacterEquipState::ECS_Count);
const int next = ((static_cast<int>(State)) + 1) % count;
return static_cast<ECharacterEquipState>(next);
}
/*And the call to swap weapon style: ( I was reticent to use a while loop, but decided it was the most efficient solution, I was originally recursively calling the function, but moved away from that during debugging. ) */
void AEchoCharacter::EchoSwapStyle()
{
const UEnum* Enum = StaticEnum<ECharacterEquipState>();
const FText Display = Enum->GetDisplayNameTextByValue(static_cast<int64>(CurrentEquipState));
if (GEngine) GEngine->AddOnScreenDebugMessage(2, 30.f, FColor::Blue, Display.ToString());
ECharacterEquipState DesiredState;
DesiredState = NextState(CurrentEquipState);
while (!(EquippedWeapon->CanUseStyle(DesiredState)))
DesiredState = NextState(DesiredState);
CurrentEquipState = DesiredState;
const FText Display2 = Enum->GetDisplayNameTextByValue(static_cast<int64>(CurrentEquipState));
if (GEngine) GEngine->AddOnScreenDebugMessage(3, 30.f, FColor::Blue, Display2.ToString());
}```
Top comments (0)