VS 2013: Error C2039: 'InitVelocity'

Hi,
I am following the First Person Shooter C++ Tutorial
(A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums)
When i copy the code below:

void AFPSProjectile::InitVelocity(const FVector& ShootDirection)
{
    if (ProjectileMovement)
    {
        // set the projectile's velocity to the desired direction
        ProjectileMovement->Velocity = ShootDirection * ProjectileMovement->InitialSpeed;
    }
}

i got this error Error 19 error C2039: ‘InitVelocity’ : is not a member of ‘AFPSProjectile’

I didn’t add or change anything and i am using UE 4.2.1.

Thanks

Hi Cobra,

Can you please verify that you have the following lines inside your FPSProjectile.h file:

/** inits velocity of the projectile in the shoot direction */
void InitVelocity(const FVector& ShootDirection);

Thank you for your answer.
Yes, I did but I still receive the same error.

Could you please provide the code for your FPSProjectile.cpp and .h files?

#include “BlackHawk.h”
#include “BHProjectile.h”

ABHProjectile::ABHProjectile(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{

// Use a sphere as a simple collision representation
CollisionComp = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("SphereComp"));
CollisionComp->InitSphereRadius(15.0f);
RootComponent = CollisionComp;

// Use a ProjectileMovementComponent to govern this projectile's movement
ProjectileMovement = PCIP.CreateDefaultSubobject<UProjectileMovementComponent>(this, TEXT("ProjectileComp"));
ProjectileMovement->UpdatedComponent = CollisionComp;
ProjectileMovement->InitialSpeed = 3000.f;
ProjectileMovement->MaxSpeed = 3000.f;
ProjectileMovement->bRotationFollowsVelocity = true;
ProjectileMovement->bShouldBounce = true;
ProjectileMovement->Bounciness = 0.3f;

}

/** inits velocity of the projectile in the shoot direction */
void InitVelocity(const FVector& ShootDirection);

#pragma once

#include “GameFramework/Actor.h”
#include “BHProjectile.generated.h”

/**
*
*/
UCLASS()
class ABHProjectile : public AActor
{
GENERATED_UCLASS_BODY()

/** Sphere collision component */
UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
TSubobjectPtr<USphereComponent> CollisionComp;

/** Projectile movement component */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement)
	TSubobjectPtr<class UProjectileMovementComponent> ProjectileMovement;

};

/** inits velocity of the projectile in the shoot direction */
void InitVelocity(const FVector& ShootDirection);

Can you please provide the header file, too?

You are declaring your function outside of your class, simply move the line after the closing bracket in your class body and you’re done :wink:
Here is the code

 #pragma once
    #include "GameFramework/Actor.h"
    #include "BHProjectile.generated.h"

 UCLASS() 
 class ABHProjectile : public AActor 
 { 
 GENERATED_UCLASS_BODY()

/** Sphere collision component */
UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
TSubobjectPtr<USphereComponent> CollisionComp;

/** Projectile movement component */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement)
    TSubobjectPtr<class UProjectileMovementComponent> ProjectileMovement;

      /** inits velocity of the projectile in the shoot direction */ 
      void InitVelocity(const FVector& ShootDirection);
};

Ok I see your failure and answered now :wink: