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"

Projectile Parameter Issues (C++)

I've been following the UE4 First Person C++ Tutorial, and so far, I have been able to figure out the things that the tutorial left out (since it was made in 4.15). But I have been trying this one for awhile, and I cant seem to figure out the problem. I know that it has to do with the setup of my projectile's movement parameters, but nothing I seem to do works. The project name is LearningCurve. Is there something that I'm missing?

LearningCurveProjectile.cpp

 #include "LearningCurveProjectile.h"
 #include "Components/SphereComponent.h"
 #include "GameFramework/ProjectileMovementComponent.h"
 
 
 // Sets default values
 ALearningCurveProjectile::ALearningCurveProjectile()
 {
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
 
     // Use a sphere as simple collision representation
     CollisionComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
     // Set the collision radius
     CollisionComponent->InitSphereRadius(15.0f);
     // Set root component to collision component
     RootComponent = CollisionComponent;
 
     // Use this component to drive this projectile's movement.
     ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
     ProjectileMovementComponent->SetUpdatedComponent(CollisionComponent);
     ProjectileMovementComponent->InitialSpeed = 3000.0f;
     ProjectileMovementComponent->MaxSpeed = 3000.0f;
     ProjectileMovementComponent->bRotationFollowsVelocity = true;
     ProjectileMovementComponent->bShouldBounce = true;
     ProjectileMovementComponent->Bounciness = 0.3f;
 
 }
 
 // Called when the game starts or when spawned
 void ALearningCurveProjectile::BeginPlay()
 {
     Super::BeginPlay();
     
 }
 
 // Called every frame
 void ALearningCurveProjectile::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
 
 }
 
 // Function that initializes the projectile's velocity in the shoot direction.
 void ALearningCurveProjectile::FireInDirection(const FVector& ShootDirection)
 {
     ProjectileMovementComponent->Velocity = ShootDirection * ProjectileMovementComponent->InitialSpeed;
 }

LearningCurveProjectile.h

 #include "CoreMinimal.h"
 #include "GameFramework/Actor.h"
 #include "LearningCurveProjectile.generated.h"
 
 UCLASS()
 class LERANINGCURVE_API ALearningCurveProjectile : public AActor
 {
     GENERATED_BODY()
     
 public:    
     // Sets default values for this actor's properties
     ALearningCurveProjectile();
 
 protected:
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
 
 public:    
     // Called every frame
     virtual void Tick(float DeltaTime) override;
 
     // Sphere collision component.
     UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
         USphereComponent* CollisionComponent;
 
     // Projectile movement component.
     UPROPERTY(VisibleAnywhere, Category = Movement)
         UProjectileMovementComponent* ProjectileMovementComponent;
     
     // Function that initializes the projectile's velocity in the shoot direction.
     void FireInDirection(const FVector& ShootDirection);
 };
Product Version: UE 4.18
Tags:
more ▼

asked Mar 03 '18 at 06:09 AM in C++ Programming

avatar image

Slaeh_
26 5 1

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

1 answer: sort voted first

This looks fine, for the projectile. But where is the code that calls SpawnActor to actually create it and put it in the scene?

Also, if you Create a new project, pick C++ project, and base it on the First Person example, it will generate all the C++ code needed to do what you're asking. I'm fairly certain the tutorial you're following was incorporated into that template. And even if you want to continue learning with your manually built project, it would still serve as a good reference project with a working example.

more ▼

answered Mar 03 '18 at 06:41 AM

avatar image

Inconceivable
27 3 3 12

avatar image Slaeh_ Mar 03 '18 at 09:39 PM

It's not exactly a problem with spawning the projectile, but more just setting up the projectile (the error was occurring before I put in the firing mechanic).

Here are the build logs if that helps alt text

errors.png (78.8 kB)
avatar image Inconceivable Mar 03 '18 at 11:22 PM

Ah, I see. So you've correctly included the headers for the UProjectileMovementComponent and USphereComponent in your LearningCurveProjectile.cpp, but you haven't forward declared those classes in the header that specifies them. Add these lines to LearningCurveProjectile.h after your included headers:

 class USphereComponent;
 class UProjectileMovementComponent;

When you get an error like "missing type specifier", try to look at the line it refers to (28) and figure out why the code doesn't know what that type is. Generally you either need to have an include file pointing to the type's definition, or forward declare the type (if it's only being used as a pointer and you're planning to include the header in a different source file)

(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