Я продолжаю получать ошибки для учебника UE4 FPS Раздел 3.1. Что я должен делать? - PullRequest
0 голосов
/ 17 июня 2020

Для следующих кодов я должен добавить снаряд и уметь стрелять им, но строки кода, предоставленные UE4 для этого, не компилируются. Всякий раз, когда я компилирую, он выдает несколько кодов ошибок. Ниже приведены коды, используемые для этого проекта.

FPSProjectile.h

#pragma once

#include "GameFramework/Actor.h"
#include "FPSProjectile.generated.h"

UCLASS()
class FPSPROJECT_API AFPSProjectile : public AActor
{
    GENERATED_BODY()

public:
    // Sets default values for this actor's properties
    AFPSProjectile();

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

public:
    // Called every frame
    virtual void Tick( float DeltaSeconds ) 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);
};

FPSCharacter. cpp

#include "FPSProject.h"
#include "FPSCharacter.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()
{
}

FPSCharacter.h

#pragma once

#include "GameFramework/Character.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)
    class 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;
};

FPSProjectile. cpp

#include "FPSProject.h"
#include "FPSProjectile.h"

// Sets default values
AFPSProjectile::AFPSProjectile()
{
    // 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 a simple collision representation.
    CollisionComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
    // Set the sphere's collision radius.
    CollisionComponent->InitSphereRadius(15.0f);
    // Set the root component to be the 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 AFPSProjectile::BeginPlay()
{
    Super::BeginPlay();

}

// Called every frame
void AFPSProjectile::Tick( float DeltaTime )
{
    Super::Tick( DeltaTime );

}

// Function that initializes the projectile's velocity in the shoot direction.
void AFPSProjectile::FireInDirection(const FVector& ShootDirection)
{
    ProjectileMovementComponent->Velocity = ShootDirection * ProjectileMovementComponent->InitialSpeed;
}

Ниже приведены ошибки, которые я получаю

error «FPSCharacter.generated.h уже включен, в FPSCharacter.h отсутствует '#pragma once' "^ / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSCharacter. cpp: 16: 23: ошибка: доступ к члену неполного типа 'class UCameraComponent' FPSCameraComponent-> SetupAttachment (GetCapsuleComponent ()); ^ / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSCharacter.h: 50: 11: примечание: предварительное объявление класса UCameraComponent UCameraComponent * FPSCameraComponent; ^ / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSCharacter. cpp: 18: 23: ошибка: доступ к члену в неполный тип 'class UCameraComponent' FPSCameraComponent-> SetRelativeLocation (FVector (0.0f, 0.0f , 50.0f + BaseEyeHeight)); ^ / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSCharacter.h: 50: 11: примечание: предварительное объявление класса UCameraComponent UCameraComponent * FPSCameraComponent; ^ / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSCharacter. cpp: 20: 23: ошибка: доступ к члену неполного типа «класс UCameraComponent» FPSCameraComponent-> bUsePawnControlRotation = true; ^ / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSCharacter.h: 50: 11: примечание: предварительное объявление класса UCameraComponent UCameraComponent * FPSCameraComponent; ^ / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSCharacter. cpp: 27: 30: ошибка: невозможно инициализировать параметр типа 'USceneComponent ' с lvalue типа 'class UCameraComponent' FPSMe sh -> SetupAttachment (FPSCameraComponent); ^ ~~~~~~~~~~~~~~~~~ /Users/apple/UE_4.25/Engine/Source/Runtime/Engine/Classes/Components/SceneComponent.h:653:40: note: прохождение аргумент параметра InParent здесь void SetupAttachment (USceneComponent InParent, FName InSocketName = NAME_None); ^ В файле, включенном в / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSProjectile. cpp: 4: / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSProjectile.h: 27 : 5: ошибка: неизвестное имя типа 'USphereComponent' USphereComponent CollisionComponent; ^ В файле, включенном в / Users / apple / Documents / Unreal Projects / FPSProject / Intermediate / Build / Mac / UE4Editor / Inc / FPSProject / FPSProjectile.gen. cpp: 8: / Users / apple / Documents / Unreal Projects / FPSProject /Source/FPSProject/FPSProjectile.h:27:5: ошибка: неизвестное имя типа 'USphereComponent' USphereComponent * CollisionComponent; ^ / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSProjectile.h: 31: 5: ошибка: неизвестное имя типа 'UProjectileMovementComponent'; Вы имели в виду "UPawnMovementComponent"? UProjectileMovementComponent * ProjectileMovementComponent; ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~ UPawnMovementComponent /Users/apple/UE_4.25/Engine/Source/Runtime/Engine/Classes/GameFramework/ Pawn.h: 23: 7: примечание: здесь объявлен UPawnMovementComponent class UPawnMovementComponent; ^ В файле, включенном из / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSProjectile. cpp: 4: / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSProjectile.h: 11 : 5: ошибка: невозможно инициализировать возвращаемый объект типа 'UObject *' с rvalue типа 'AFPSProjectile *' GENERATED_BODY () ^ ~~~~~~~~~~~~~~~ / Users / apple / UE_4. 25 / Engine / Source / Runtime / CoreUObject / Public / UObject / ObjectMacros.h: 616: 29: примечание: расширено из макроса 'GENERATED_BODY'

определить GENERATED_BODY (...) BODY_MACRO_COMBINE (CURRENT_FILE_ID, _, , _GENERATED_BODY); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ /Users/apple/UE_4.25/Engine/Source/Runtime/CoreUObject/Public/UObject/ObjectMacros.h:611:37: примечание: расширено из макроса 'BODY_MACRO_COMBINE'

определить BODY_MACRO_COMBINE (A, B, C, D) BODY_MACRO_COMBINE_INNER (A, B, C, D) ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ /Users/apple/UE_4.25/Engine/Source/Runtime/CoreUObject/Public/UObject/ObjectMacros.h:610:43: примечание: расширено из макроса 'BODY_MACRO_COMBINE_INNER'

define BODY_MACRO_COMBINE_INNER (A, B, C, D) A ## B ## C ## D ^ ~~~~~~~~~ Примечание: (пропуская 1 раскрытие в backtrace; используйте -fmacro-backtrace -limit = 0, чтобы увидеть все) / Users / apple / Documents / Unreal Projects / FPSProject / Intermediate / Build / Mac / UE4Editor / Inc / FPSProject / FPSProjectile.generated.h: 82: 2: примечание: расширено из макроса 'FPSProject_Source_FPSProject_FPSProjectile_OD_GOD_11_ FPSProject_Source_FPSProject_FPSProjectile_h_11_ENHANCED_CONSTRUCTORS \ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~ ~ / Users / apple / Documents / Unreal Projects / FPSProject / Intermediate / Build / Mac / UE4Editor / Inc / FPSProject / FPSProjectile.generated.h: 56: 58: примечание: расширено из макроса 'FPSProject_Source_FPSProject_FPSProjectile_h_11_ENHANCED_CONCED_CONTARCED_CONTOR_CONCAD_CONCAD_11_ENHANCED_CONCED_CONCED_CONCAD_CONTOR_C \ ^ /Users/apple/UE_4.25/Engine/Source/Runtime/CoreUObject/Public/UObject/ObjectMacros.h:1588:11: примечание: расширено из макроса '\ DEFINE_VTABLE_PTR_HELPER_CTOR_CALLER' return new (EC_InternalUseOnlyConstructor) (* UTransstructor) (), NAME_None, RF_NeedLoad | RF_ClassDefaultObject | RF_TagGarbageTemp) TClass (Помощник); \ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ / Users / apple / Documents / Unreal Projects / FPSProject / Source / FPSProject / FPSProjectile.h: 31: 5: ошибка: неизвестное имя типа 'UProjectileMovementComponent'; Вы имели в виду "UPawnMovementComponent"? UProjectileMovementComponent * ProjectileMovementComponent; ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~ UPawnMovementComponent /Users/apple/UE_4.25/Engine/Source/Runtime/Engine/Classes/GameFramework/ Pawn.h: 23: 7: примечание: здесь объявлен UPawnMovementComponent class UPawnMovementComponent; ^

...