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"

Can't compile fire mechanic

I cannot compile step 3.2 of this tutorial: https://docs.unrealengine.com/en-us/Programming/Tutorials/FirstPersonShooter/3 I've tried to search it on the internet, but it seems to be a C++ error. Build errors:

   C:\Users\My_Username\Documents\Unreal Projects\FPSProject\Binaries\Win64\UE4Editor-FPSProject-4739.dll : fatal error LNK1120: 1 unresolved externals
   FPSCharacter.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl AFPSProjectile::FireInDirection(struct FVector const &)" (?FireInDirection@AFPSProjectile@@QEAAXAEBUFVector@@@Z) referenced in function "public: void __cdecl AFPSCharacter::Fire(void)" (?Fire@AFPSCharacter@@QEAAXXZ)


My code: FPSCharacter.cpp

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "FPSCharacter.h"
 #include "FPSProject.h"
 #include "FPSProjectile.h"
 #include <Camera/Cameracomponent.h>
 
 // Sets default values
 AFPSCharacter::AFPSCharacter()
 {
     // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it
     PrimaryActorTick.bCanEverTick = true;
 
     // Create a first person camera component
     FPSCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
     // Attach the camera component to our capsule component
     FPSCameraComponent->SetupAttachment(GetCapsuleComponent());
     // Position the camera slightly above the eyes
     FPSCameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f + BaseEyeHeight));
     // Allow the pawn to control camera rotation
     FPSCameraComponent->bUsePawnControlRotation = true;
 
     // Create a first person mesh component for the owning player
     FPSMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("FirstPersonMesh"));
     // Only the owning player sees this mesh
     FPSMesh->SetOnlyOwnerSee(true);
     // Attach the FPS mesh to the FPS camera
     FPSMesh->SetupAttachment(FPSCameraComponent);
     // Disable some environmental shadowing to preserve the illusion of having a single mesh
     FPSMesh->bCastDynamicShadow = false;
     FPSMesh->CastShadow = false;
 
     // The owning player doesn't see the regular (third-person) body mesh
     GetMesh()->SetOwnerNoSee(true);
 }
 
 // Called when the game starts or when spawned
 void AFPSCharacter::BeginPlay()
 {
     Super::BeginPlay();
 
     if (GEngine)
     {
         // Put up a debug message for five seconds. The -1 "Key" value (first argument) indicates that we will never need to update or refresh this message
         GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("We are using FPSCharacter."));
     }
 }
 
 // Called every frame
 void AFPSCharacter::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
 
 }
 
 // Called to bind functionality to input
 void AFPSCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
 {
     Super::SetupPlayerInputComponent(PlayerInputComponent);
 
     // Set up "movement" bindings
     PlayerInputComponent->BindAxis("MoveForward", this, &AFPSCharacter::MoveForward);
     PlayerInputComponent->BindAxis("MoveRight", this, &AFPSCharacter::MoveRight);
     // Set up "look" bindings
     PlayerInputComponent->BindAxis("Turn", this, &AFPSCharacter::AddControllerYawInput);
     PlayerInputComponent->BindAxis("LookUp", this, &AFPSCharacter::AddControllerPitchInput);
     // Set up "action" bindings
     PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &AFPSCharacter::StartJump);
     PlayerInputComponent->BindAction("Jump", IE_Released, this, &AFPSCharacter::StopJump);
     PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &AFPSCharacter::Fire);
 }
 
 void AFPSCharacter::MoveForward(float Value)
 {
     // Find out which way is "forward" and record that the player wants to move that way
     FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::X);
     AddMovementInput(Direction, Value);
 }
 
 void AFPSCharacter::MoveRight(float Value)
 {
     // Find out which way is "right" and record that the player wants to move that way
     FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::Y);
     AddMovementInput(Direction, Value);
 }
 
 void AFPSCharacter::StartJump()
 {
     bPressedJump = true;
 }
 
 void AFPSCharacter::StopJump()
 {
     bPressedJump = false;
 }
 
 void AFPSCharacter::Fire()
 {
     // Attempt to fire a projectile
     if (ProjectileClass)
     {
         // Get the camera transform
         FVector CameraLocation;
         FRotator CameraRotation;
         GetActorEyesViewPoint(CameraLocation, CameraRotation);
 
         // Transform MuzzleOffset from camera space to world space
         FVector MuzzleLocation = CameraLocation + FTransform(CameraRotation).TransformVector(MuzzleOffset);
         FRotator MuzzleRotation = CameraRotation;
         // Skew the aim to be slightly upwards
         MuzzleRotation.Pitch += 10.0f;
         UWorld* World = GetWorld();
         if (World)
         {
             FActorSpawnParameters SpawnParams;
             SpawnParams.Owner = this;
             SpawnParams.Instigator = Instigator;
             // Spawn the projectile at the muzzle
             AFPSProjectile* Projectile = World->SpawnActor<AFPSProjectile>(ProjectileClass, MuzzleLocation, MuzzleRotation, SpawnParams);
             if (Projectile)
             {
                 // Set the projectile's initial trajectory
                 FVector LaunchDirection = MuzzleRotation.Vector();
                 Projectile->FireInDirection(LaunchDirection);
             }
         }
     }
 }


FPSCharacter.h

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #pragma once
 
 #include "CoreMinimal.h"
 #include "GameFramework/Character.h"
 #include <Camera/CameraComponent.h>
 #include "FPSCharacter.generated.h"
 
 
 
 UCLASS()
 class FPSPROJECT_API AFPSCharacter : public ACharacter
 {
     GENERATED_BODY()
 
 public:
     // Sets default values for this character's properties
     AFPSCharacter();
 
 protected:
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
 
 public:
     // Called every frame
     virtual void Tick(float DeltaSeconds) override;
 
     // Called to bind functionality to input
     virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
 
     // Handles input for moving forward and backward
     UFUNCTION()
     void MoveForward(float Value);
     // Handles input for moving right and left
     UFUNCTION()
     void MoveRight(float Value);
     // Sets jump flag when key is pressed
     UFUNCTION()
     void StartJump();
     // Clears jump flag when key is released
     UFUNCTION()
     void StopJump();
     // Function that handles firing projectiles
     UFUNCTION()
     void Fire();
     // FPS camera
     UPROPERTY(VisibleAnywhere)
     UCameraComponent* FPSCameraComponent;
     // First-person mesh (arms), visible only to the owning player
     UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
     USkeletalMeshComponent* FPSMesh;
     // Gun muzzle's offset from the camera location
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
     FVector MuzzleOffset;
     // Projectile class to spawn
     UPROPERTY(EditDefaultsOnly, Category = Projectile)
     TSubclassOf<class AFPSProjectile> ProjectileClass;
 };




Product Version: UE 4.22 Preview
Tags:
more ▼

asked Mar 25 '19 at 03:05 PM in C++ Programming

avatar image

jubiman
1 2

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

1 answer: sort voted first

I'm stupid, so sorry. I forgot to declare the FireInDirection in my projectile.cpp. I have solved it and its all fine now, just had to but some more time into it...

more ▼

answered Mar 29 '19 at 03:54 PM

avatar image

jubiman
1 2

(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