UPDATE:
I have found the solution on here https://answers.unrealengine.com/questions/658827/camera-issue-in-tutorial.html
=============
UE4.16.3, 第一人称视角教程此步报错: 2.7 - 更改摄像机视图 , 可能是什么原因呢?
Build:
[mw_shl_code=cpp,true]1>------ 已启动生成: 项目: UE4, 配置: BuiltWithUnrealBuildTool Win32 ------
2>------ 已启动生成: 项目: FPSProject, 配置: Development_Editor x64 ------
2> Compiling game modules for hot reload
2> Performing 3 actions (4 in parallel)
2> FPSCharacter.cpp
2>D:\work\ue-project\FPSProject\Source\FPSProject\FPSCharacter.cpp(15): error C2664: “void USceneComponent::SetupAttachment(USceneComponent *,FName)”: 无法将参数 1 从“UCapsuleComponent *”转换为“USceneComponent *”
2> D:\work\ue-project\FPSProject\Source\FPSProject\FPSCharacter.cpp(15): note: 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
2>ERROR : UBT error : Failed to produce item: D:\work\ue-project\FPSProject\Binaries\Win64\UE4Editor-FPSProject-8701.dll
2> Total build time: 10.05 seconds (Local executor: 0.00 seconds)
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(37,5): error MSB3075: 命令“C:\EpicGames\UE_4.16\Engine\Build\BatchFiles\Build.bat FPSProjectEditor Win64 Development "D:\work\ue-project\FPSProject\FPSProject.uproject" -waitmutex”已退出,代码为 5。请验证您是否有足够的权限来运行此命令。
========== 生成: 成功 1 个,失败 1 个,最新 0 个,跳过 0 个 ==========[/mw_shl_code]
----------------
Header:
[mw_shl_code=cpp,true]// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Camera/CameraComponent.h"
#include "Engine/World.h"
#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 DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
// 处理前后移动的输入。
UFUNCTION()
void MoveForward(float Value);
// 处理左右移动的输入。
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();
UPROPERTY(VisibleAnywhere)
UCameraComponent* FPSCameraComponent;
};
[/mw_shl_code]
----------
CPP
[mw_shl_code=cpp,true]// Fill out your copyright notice in the Description page of Project Settings.
#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;
}
// Called when the game starts or when spawned
void AFPSCharacter::BeginPlay()
{
Super::BeginPlay();
if (GEngine)
{
// 显示调试信息五秒。-1“键”值(首个参数)说明我们无需更新或刷新此消息。
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(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);
}
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;
}
[/mw_shl_code]
|