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"

VS 2013: Error C2039: 'InitVelocity'

Hi, I am following the First Person Shooter C++ Tutorial (https://wiki.unrealengine.com/First_Person_Shooter_C%2B%2B_Tutorial) 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

Product Version: Not Selected
Tags:
more ▼

asked Jun 27 '14 at 12:17 AM in C++ Programming

avatar image

Cobra
5 1 3 4

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

2 answers: sort voted first

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 ;) 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);
 };





more ▼

answered Jul 03 '14 at 01:38 AM

avatar image

birdfreeyahoo
870 46 44 80

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

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);
more ▼

answered Jun 30 '14 at 09:46 PM

avatar image Cobra Jul 02 '14 at 08:14 PM

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

avatar image Tim C ♦♦ STAFF Jul 02 '14 at 08:59 PM

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

avatar image Cobra Jul 03 '14 at 12:04 AM

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);

avatar image birdfreeyahoo Jul 03 '14 at 12:15 AM

Can you please provide the header file, too?

avatar image Cobra Jul 03 '14 at 12:26 AM

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);

avatar image birdfreeyahoo Jul 03 '14 at 01:39 AM

Ok I see your failure and answered now ;)

(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