虚幻文档中教程项目中的错误
Errors in tutorial project from Unreal's documentation
我是第一次尝试学习C++/UE4,教程中提供的代码(在他们自己的文档中(抛出了错误。我怎样才能解决这个问题和/或找到一个有效的教程?
我正在尝试在 https://docs.unrealengine.com/en-US/Programming/Tutorials/PlayerInput/index.html 完成本教程,但步骤 1 中提供的代码抛出错误。
我已经尝试了"潜在修复"并在网上四处寻找,但没有找到任何可以修复错误的东西。
AMyPawn::AMyPawn(( { 设置此棋子以每帧调用 Tick((。 如果不需要,可以将其关闭以提高性能。 PrimaryActorTick.bCanEverTick = true;
// Set this pawn to be controlled by the lowest-numbered player
AutoPossessPlayer = EAutoReceiveInput::Player0;
// Create a dummy root component we can attach things to.
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
// Create a camera and a visible object
UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OurCamera"));
OurVisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OurVisibleComponent"));
// Attach our camera and visible object to our root component. Offset and rotate the camera.
OurCamera->SetupAttachment(RootComponent);
OurCamera->SetRelativeLocation(FVector(-250.0f, 0.0f, 250.0f));
OurCamera->SetRelativeRotation(FRotator(-45.0f, 0.0f, 0.0f));
OurVisibleComponent->SetupAttachment(RootComponent);
}
错误 C2065"UCameraComponent":未声明的标识符
错误 C2065"我们的相机":未声明的标识符
错误 C2672"UObject::创建默认子对象":找不到匹配的重载函数
错误 C2974 "UObject::创建默认子对象":"TReturnType"的模板参数无效,类型应为
错误 MSB3075 命令"C:\Program Files\Epic Games\UE_4.22\Engine\Build\BatchFiles\Build.bat" SecondUnrealProjectEditor Win64 Development -Project="C:\Users...\SecondUnrealProject\SecondUnrealProject.uproject" -WaitMutex -FromMsBuild" 退出,代码为 5。请验证您是否有足够的权限来运行此命令。
我希望代码能够正常运行而不会出错,因为我完全按照教程进行操作(并且实际上已经复制粘贴了"工作"代码以检查我没有意外更改任何内容(
第一个错误意味着编译器找不到UCameraComponent
的声明,其他错误只是后续错误。
您需要将以下内容添加到您的MyPawn.cpp
:
#include "Camera/CameraComponent.h"
修复此问题后,您将收到另一个错误,这次是因为缺少UStaticMeshComponent
的声明。为此,您需要以下内容包括:
#include "Components/StaticMeshComponent.h"
错误消息是不同的,因为在第一种情况下,编译器想要实例化未知类型的对象,这是不可能的,而在后一种情况下,编译器想要将未知类型的指针UStaticMeshComponent
分配给另一个已知类型的指针USceneComponent
,并且它不知道UStaticMeshComponent
可以强制转换为USceneComponent
。
我同意教程错过了这一点很糟糕,但是使用正确的工具查找缺少的包含相当容易。在Visual Studio中,您只需单击任何类型(例如UCameraComponent
(,同时按住Ctrl
,它将直接转到声明,或者它将显示具有潜在声明的文件列表。
在虚幻引擎中,通常每个组件的包含文件都具有该组件的名称,因此对于UCameraComponent
,CameraComponent.h
,它驻留在子文件夹Camera
中。
我也遇到了这个问题。 我已经完成了教程并进行了一些修改。 视觉工作室 2019 14.24.28315 UE4 4.24
我的典当
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/Character.h"
#include "MyPawn.generated.h"
UCLASS()
class HOWTO_PLAYERINPUT_API AMyPawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AMyPawn();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UPROPERTY(EditAnywhere)
USceneComponent* OurVisibleComponent;
//Input functions
void Move_XAxis(float AxisValue);
void Move_YAxis(float AxisValue);
void StartGrowing();
void StopGrowing();
//Input variables
FVector CurrentVelocity;
bool bGrowing;
};
我的典当.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyPawn.h"
#include "Camera/CameraComponent.h"
#include "Components/StaticMeshComponent.h"
// Sets default values
AMyPawn::AMyPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// Set this pawn to be controlled by the lowest-numbered player
AutoPossessPlayer = EAutoReceiveInput::Player0;
// Create a dummy root component we can attach things to.
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
// Create a camera and a visible object
UPROPERTY(EditAnywhere)
UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OurCamera"));
OurVisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OurVisibleComponent"));
// Attach our camera and visible object to our root component. Offset and rotate the camera.
OurCamera->SetupAttachment(RootComponent);
OurCamera->SetRelativeLocation(FVector(-250.0f, 0.0f, 250.0f));
OurCamera->SetRelativeRotation(FRotator(-45.0f, 0.0f, 0.0f));
OurVisibleComponent->SetupAttachment(OurCamera);
OurVisibleComponent->SetRelativeLocation(FVector(268.0f, 0.0f, -14.14f));
OurVisibleComponent->SetRelativeRotation(FRotator(45.0f, 0.0f, 0.0f));
}
// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// Handle growing and shrinking based on our "Grow" action
float CurrentScale = OurVisibleComponent->GetComponentScale().X;
if (bGrowing)
{
// Grow to double size over the course of one second
CurrentScale += DeltaTime;
}
else
{
// Shrink half as fast as we grow
CurrentScale -= (DeltaTime * 0.5f);
}
// Make sure we never drop below our starting size, or increase past double size.
CurrentScale = FMath::Clamp(CurrentScale, 1.0f, 2.0f);
OurVisibleComponent->SetWorldScale3D(FVector(CurrentScale));
// Handle movement based on our "MoveX" and "MoveY" axes
if (!CurrentVelocity.IsZero())
{
FVector NewLocation = GetActorLocation() + (CurrentVelocity * DeltaTime);
SetActorLocation(NewLocation);
}
}
// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
// Respond when our "Grow" key is pressed or released.
PlayerInputComponent->BindAction("Grow", IE_Pressed, this, &AMyPawn::StartGrowing);
PlayerInputComponent->BindAction("Grow", IE_Released, this, &AMyPawn::StopGrowing);
// Respond every frame to the values of our two movement axes, "MoveX" and "MoveY".
PlayerInputComponent->BindAxis("MoveX", this, &AMyPawn::Move_XAxis);
PlayerInputComponent->BindAxis("MoveY", this, &AMyPawn::Move_YAxis);
}
void AMyPawn::Move_XAxis(float AxisValue)
{
// Move at 100 units per second forward or backward
CurrentVelocity.X = FMath::Clamp(AxisValue, -1.0f, 1.0f) * 100.0f;
}
void AMyPawn::Move_YAxis(float AxisValue)
{
// Move at 100 units per second right or left
CurrentVelocity.Y = FMath::Clamp(AxisValue, -1.0f, 1.0f) * 100.0f;
}
void AMyPawn::StartGrowing()
{
bGrowing = true;
}
void AMyPawn::StopGrowing()
{
bGrowing = false;
}
我只是觉得每次UE4更新时,基本上每个教程都会下地狱,这很疯狂。 *注意:我在完成本教程时摸索着。我是UE4的meh,没有花时间"正确"编写此代码,所以如果风格/惯例方面有任何错误,我很抱歉;)
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- 错误-我无法在VS2019中打开新的Qt项目
- 将QT项目导入Visual Studio 2019会给我带来很多LNK2001错误
- VS 2015 链接错误 无法构建依赖于 libcurl 的项目
- 尝试将 boost::stacktrace 添加到 CMake 项目时出现构建错误
- 在编译时,C++项目抛出错误 C2228,这是预期的,因为控件在运行时未达到该点
- 编译器现在遵循C++14标准,我的项目不再编译神秘的SFML错误
- 标头,包括在 Swift 项目中使用C++文件时的错误
- 从加密项目向量中解密任意选择的元素会导致无效的 PKCS #7 块错误
- 错误 MSB8040:此项目需要 Spectre 缓解的库
- xtr1common中的错误,尝试使用VS2019构建原始VS2013 C++项目时type_traits
- 如何摆脱导入的 make 项目中的 Eclipse 索引器"Type std::... could not be resolved"错误
- Eclipse/CDT_C++给出"语义错误_"类型XXX无法解决"。项目运行
- CMake 错误,在构建 VTK 'INSTALL'项目
- 欧拉项目 #8 C++ 得到错误的答案
- 编译 OpenBLAS C++项目会产生错误"Undefined symbols for architecture x86_64"
- CMAKE 错误项目文件无效;不包含 cmakelists.txt
- Cmake错误:项目中使用了以下变量,但它们被设置为NOTFOUND,试图在archlinux中编译Rigs of Ro