I am trying to make animation event for footstep. I using a enum for editor since it is nice for designers rather than putting in “int” directly and trying to remember which “int” is for what footstep type. I try and convert enum to int and it crashes.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "Animation/AnimNotifies/AnimNotify.h"
#include "Sound/SoundCue.h"
#include "CoreCharacterFootstepAnimNotify.generated.h"
class UAnimSequenceBase;
class USkeletalMeshComponent;
class USoundBase;
UENUM(BlueprintType)
enum class CoreCharacterFootstepAnimNotifyType : uint8
{
Step = 0,
Crouch = 1,
Walk_Run = 2,
Sprint = 3,
Jump = 4,
Land = 5
};
ENUM_CLASS_FLAGS(CoreCharacterFootstepAnimNotifyType)
UCLASS(const, hidecategories = Object, collapsecategories, meta = (DisplayName = "Footstep"))
class PIRATEPROJECT_API UCoreCharacterFootstepAnimNotify : public UAnimNotify
{
GENERATED_BODY()
public:
UCoreCharacterFootstepAnimNotify();
virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sound", meta = (ExposeOnSpawn = true))
USoundCue* SoundCue;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sound", meta = (ExposeOnSpawn = true))
CoreCharacterFootstepAnimNotifyType FootstepType;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "CoreCharacterFootstepAnimNotify.h"
#include "Components/SkeletalMeshComponent.h"
#include "Components/AudioComponent.h"
#include "Kismet/GameplayStatics.h"
#include "Sound/SoundBase.h"
#include "Animation/AnimSequenceBase.h"
#if WITH_EDITOR
#include "Logging/MessageLog.h"
#include "Misc/UObjectToken.h"
#endif
UCoreCharacterFootstepAnimNotify::UCoreCharacterFootstepAnimNotify()
: Super()
{
#if WITH_EDITORONLY_DATA
NotifyColor = FColor(196, 142, 255, 255);
#endif // WITH_EDITORONLY_DATA
}
void UCoreCharacterFootstepAnimNotify::Notify(class USkeletalMeshComponent* MeshComp, class UAnimSequenceBase* Animation)
{
if (SoundCue)
{
//Don't Play Any Looping Sounds
if (SoundCue->IsLooping())
{
UE_LOG(LogAudio, Warning, TEXT("PlaySound notify: Anim %s tried to spawn infinitely looping sound asset %s. Spawning suppressed."), *GetNameSafe(Animation), *GetNameSafe(SoundCue));
return;
}
UAudioComponent* AudioComponent = UGameplayStatics::SpawnSoundAttached(SoundCue, MeshComp);
AudioComponent->SetIntParameter(FName("FootstepType"), static_cast<int>(FootstepType));
}
}