Good Day!
I have child class of UAnimNotifyState and overwrite NotifyTick function using function of Utils class:
#pragma once
class Utils
{
public:
template<typename T>
static T* GetPlayerComponent(AActor* PlayerPawn)
{
if (!PlayerPawn) return nullptr;
const auto Component = PlayerPawn->GetComponentByClass(T::StaticClass());
return Cast<T>(Component);
}
};
However compiling fails because this class is not initialized:
error C2027: use of undefined type ‘Utils’
code of overwritten function:
#include "Animations/SwingNotifyState.h"
#include "Character/BaseCharacter.h"
#include "Utils.h"
#include "Character/Components/WeaponComponent.h"
#include "Weapons/Melee/BaseMeleeWeapon.h"
void USwingNotifyState::NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float FrameDeltaTime, const FAnimNotifyEventReference& EventReference)
{
if (const auto Actor = MeshComp->GetOwner())
{
if (auto WeaponComponent = Utils::GetPlayerComponent<UWeaponComponent>(Actor))
{
auto CurWeapon = WeaponComponent->GetCurrentWeapon();
if(CurWeapon->IsA(ABaseMeleeWeapon::StaticClass()))
{
CurWeapon->SwingWeapon();
}
}
}
Super::NotifyTick(MeshComp, Animation, FrameDeltaTime, EventReference);
}
Thanks in advance