So I’m not new to c++ programming, but I am new to c++ in unreal. I wanted to make an “Interactable” class, and how it’s meant to work is when a line trace that’s activated by a keypress hits it, it runs an event that can be used in blueprints to make implementation easier. I started making this using the c++ fps template. My “Interact” function is located on the character’s .cpp file. I used PlayerInputComponent->BindAction("Action", IE_Pressed, this, &ATestingGroundsCharacter::Interact);
to bind it to my “Action” input mapping. It goes as follows:
void ATestingGroundsCharacter::Interact()
{
FHitResult Hit;
FVector Start = FirstPersonCameraComponent->GetComponentLocation();
FVector End = ((FirstPersonCameraComponent->GetForwardVector() * 300.f) + Start);
FCollisionQueryParams CollisionParams;
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 2, 0, 1);
if (GetWorld()->LineTraceSingleByChannel(Hit, Start, End, ECC_Visibility, CollisionParams))
{
if (Hit.bBlockingHit)
{
if (Hit.GetActor()->GetClass()->IsChildOf(AInteractable::StaticClass()))
{
Cast<AInteractable>(Hit.GetActor())->ButtonPressed();
}
}
}
}
The ButtonPressed() Function/Event is labeled as UFUNCTION(BlueprintNativeEvent, Category = "Events")
in the .h file. Here is the function:
void AInteractable::ButtonPressed()
{
UE_LOG(LogTemp, Warning, TEXT("Pressed"));
}
in my The problem is that when I try and compile this, I get these errors:
1:
Interactable.gen.cpp.obj : error LNK2005: “public: void __cdecl AInteractable::ButtonPressed(void)” (?ButtonPressed@AInteractable@@QEAAXXZ) already defined in Interactable.cpp.obj
2:
Interactable.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl AInteractable::ButtonPressed_Implementation(void)” (?ButtonPressed_Implementation@AInteractable@@UEAAXXZ)
3:
Interactable.gen.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl AInteractable::ButtonPressed_Implementation(void)” (?ButtonPressed_Implementation@AInteractable@@UEAAXXZ)
4:
A:\Users\######\Documents\Unreal Projects\TestingGrounds\Binaries\Win64\UE4Editor-TestingGrounds-0289.dll : fatal error LNK1120: 1 unresolved externals
(I censored my windows user.)
Could anyone help me out?