x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Trying to run a function from a line trace gives an error.

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?

Product Version: UE 4.22
Tags:
more ▼

asked Jun 07 '19 at 10:37 AM in C++ Programming

avatar image

Rusty Bandwagon
1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Is your button pressed function marked as a BlueprintNativeEvent in its UFUNCTION tag? If so, you'll need to call your function ButtonPressed_Implementation instead of ButtonPressed.

more ▼

answered Jun 07 '19 at 03:10 PM

avatar image

Reuben Ward
343 8 4 16

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question