Hi dear Epic stuff
I was following this tutorial : Quick Start Guide to Player-Controlled Cameras in Unreal Engine CPP | Unreal Engine 5.2 Documentation
After finished with writing code. I tried opening project. But engine crashed when initializing.
Then i created a new blank project. And added the same class and only that class. Made necessery editing. Engine crashed when opening that project also.
VS2013 gives no error or warnings when building the project.
Engine Version 4.7.4, Os : Win 7 SP1, VS2013
It is a bit long, but i tried to give as much info as possible.
This is the crash report(For second blank project)
MachineId:839FFFF94FE0B8C176196598B3B1E235
EpicAccountId:806d36664f024562b2ddef02bfdb062d
Access violation - code c0000005 (first/second chance not available)
UE4Editor_Engine!USceneComponent::AttachTo() + 79 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\engine\private\scenecomponent.cpp:864]
UE4Editor_MyProject2!APawnWithCamera::APawnWithCamera() + 320 bytes [c:\dosyalar\ue4projects\myproject2\source\myproject2\pawnwithcamera.cpp:16]
UE4Editor_CoreUObject!UClass::CreateDefaultObject() + 435 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\class.cpp:2535]
UE4Editor_CoreUObject!UObjectLoadAllCompiledInDefaultProperties() + 805 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:739]
UE4Editor_CoreUObject!ProcessNewlyLoadedUObjects() + 146 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:815]
UE4Editor_CoreUObject!TBaseStaticDelegateInstance<void __cdecl(void)>::ExecuteIfSafe() + 7 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:921]
UE4Editor_Core!TBaseMulticastDelegate<void>::Broadcast() + 149 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\public\delegates\delegatesignatureimpl_variadics.inl:1030]
UE4Editor_Core!FModuleManager::LoadModuleWithFailureReason() + 2194 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\private\modules\modulemanager.cpp:359]
UE4Editor_Projects!FModuleDescriptor::LoadModulesForPhase() + 784 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\projects\private\moduledescriptor.cpp:350]
UE4Editor_Projects!FProjectManager::LoadModulesForProject() + 581 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\projects\private\projectmanager.cpp:53]
UE4Editor!FEngineLoop::LoadStartupModules() + 705 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launchengineloop.cpp:1863]
UE4Editor!FEngineLoop::PreInit() + 11141 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launchengineloop.cpp:1400]
UE4Editor!GuardedMain() + 251 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launch.cpp:110]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]
This is the code i wrote
First projects header
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Pawn.h"
#include "PawnWithCamera.generated.h"
UCLASS()
class MYPROJECT_API APawnWithCamera : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
APawnWithCamera();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
USpringArmComponent* OurCameraSpringArm;
UCameraComponent* OurCamera;
FVector2D MovementInput;
FVector2D CameraInput;
float ZoomFactor;
bool bZoomIn;
void MoveForward(float AxisValue);
void MoveRight(float AxisValue);
void ZoomIn();
void ZoomOut();
void CameraPitch(float AxisValue);
void CameraYaw(float AxisValue);
};
First projects Source
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyProject.h"
#include "PawnWithCamera.h"
// Sets default values
APawnWithCamera::APawnWithCamera()
{
// 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;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
OurCameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
OurCamera->AttachTo(RootComponent);
OurCamera->SetRelativeLocationAndRotation(FVector(0.f, 0.f, 50.f), FRotator(-60.f, 0.f, 0.f));
OurCameraSpringArm->TargetArmLength = 400.f;
OurCameraSpringArm->bEnableCameraLag = true;
OurCameraSpringArm->CameraLagSpeed = 3.f;
OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("GameCamera"));
OurCamera->AttachTo(OurCameraSpringArm);
AutoPossessPlayer = EAutoReceiveInput::Player0;
}
// Called when the game starts or when spawned
void APawnWithCamera::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void APawnWithCamera::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
if (bZoomIn)
{
ZoomFactor += DeltaTime * 0.5f;
}
else
{
ZoomFactor -= DeltaTime * 0.25f;
}
ZoomFactor = FMath::Clamp<float>(ZoomFactor, 0.f, 1.f);
OurCamera->FieldOfView = FMath::Lerp<float>(90.f, 60.f, ZoomFactor);
OurCameraSpringArm->TargetArmLength = FMath::Lerp<float>(400.f, 300.f, ZoomFactor);
{
FRotator NewRotation = GetActorRotation();
NewRotation.Yaw += CameraInput.X;
SetActorRotation(NewRotation);
}
{
FRotator NewRotation = OurCameraSpringArm->GetComponentRotation();
NewRotation.Pitch = FMath::Clamp(NewRotation.Pitch + CameraInput.Y, -80.f, -15.f);
OurCameraSpringArm->SetWorldRotation(NewRotation);
}
if (!MovementInput.IsZero())
{
MovementInput = MovementInput.GetSafeNormal() * 100.f;
FVector NewLocation = GetActorLocation();
NewLocation += GetActorForwardVector() * MovementInput.X * DeltaTime;
NewLocation += GetActorRightVector() * MovementInput.Y * DeltaTime;
SetActorLocation(NewLocation);
}
}
// Called to bind functionality to input
void APawnWithCamera::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
InputComponent->BindAction("ZoomIn", IE_Pressed, this, &APawnWithCamera::ZoomIn);
InputComponent->BindAction("ZoomIn", IE_Released, this, &APawnWithCamera::ZoomOut);
InputComponent->BindAxis("MoveForward", this, &APawnWithCamera::MoveForward);
InputComponent->BindAxis("MoveRight", this, &APawnWithCamera::MoveRight);
InputComponent->BindAxis("CameraPitch", this, &APawnWithCamera::CameraPitch);
InputComponent->BindAxis("CameraYaw", this, &APawnWithCamera::CameraYaw);
}
void APawnWithCamera::MoveForward(float AxisValue)
{
MovementInput.X = FMath::Clamp(AxisValue, -1.f, 1.f);
}
void APawnWithCamera::MoveRight(float AxisValue)
{
MovementInput.Y = FMath::Clamp(AxisValue, -1.f, 1.f);
}
void APawnWithCamera::ZoomIn()
{
bZoomIn = true;
}
void APawnWithCamera::ZoomOut()
{
bZoomIn = false;
}
void APawnWithCamera::CameraPitch(float AxisValue)
{
CameraInput.Y = AxisValue;
}
void APawnWithCamera::CameraYaw(float AxisValue)
{
CameraInput.X = AxisValue;
}
Header and Source for second blank test project
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Pawn.h"
#include "PawnWithCamera.generated.h"
UCLASS()
class MYPROJECT2_API APawnWithCamera : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
APawnWithCamera();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
USpringArmComponent* OurCameraSpringArm;
UCameraComponent* OurCamera;
FVector2D MovementInput;
FVector2D CameraInput;
float ZoomFactor;
bool bZoomIn;
void MoveForward(float AxisValue);
void MoveRight(float AxisValue);
void ZoomIn();
void ZoomOut();
void CameraPitch(float AxisValue);
void CameraYaw(float AxisValue);
};
This is the source for second project
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyProject2.h"
#include "PawnWithCamera.h"
// Sets default values
APawnWithCamera::APawnWithCamera()
{
// 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;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
OurCameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
OurCamera->AttachTo(RootComponent);
OurCamera->SetRelativeLocationAndRotation(FVector(0.f, 0.f, 50.f), FRotator(-60.f, 0.f, 0.f));
OurCameraSpringArm->TargetArmLength = 400.f;
OurCameraSpringArm->bEnableCameraLag = true;
OurCameraSpringArm->CameraLagSpeed = 3.f;
OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("GameCamera"));
OurCamera->AttachTo(OurCameraSpringArm);
AutoPossessPlayer = EAutoReceiveInput::Player0;
}
// Called when the game starts or when spawned
void APawnWithCamera::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void APawnWithCamera::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
if (bZoomIn)
{
ZoomFactor += DeltaTime * 0.5f;
}
else
{
ZoomFactor -= DeltaTime * 0.25f;
}
ZoomFactor = FMath::Clamp<float>(ZoomFactor, 0.f, 1.f);
OurCamera->FieldOfView = FMath::Lerp<float>(90.f, 60.f, ZoomFactor);
OurCameraSpringArm->TargetArmLength = FMath::Lerp<float>(400.f, 300.f, ZoomFactor);
{
FRotator NewRotation = GetActorRotation();
NewRotation.Yaw += CameraInput.X;
SetActorRotation(NewRotation);
}
{
FRotator NewRotation = OurCameraSpringArm->GetComponentRotation();
NewRotation.Pitch = FMath::Clamp(NewRotation.Pitch + CameraInput.Y, -80.f, -15.f);
OurCameraSpringArm->SetWorldRotation(NewRotation);
}
if (!MovementInput.IsZero())
{
MovementInput = MovementInput.GetSafeNormal() * 100.f;
FVector NewLocation = GetActorLocation();
NewLocation += GetActorForwardVector() * MovementInput.X * DeltaTime;
NewLocation += GetActorRightVector() * MovementInput.Y * DeltaTime;
SetActorLocation(NewLocation);
}
}
// Called to bind functionality to input
void APawnWithCamera::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
InputComponent->BindAction("ZoomIn", IE_Pressed, this, &APawnWithCamera::ZoomIn);
InputComponent->BindAction("ZoomIn", IE_Released, this, &APawnWithCamera::ZoomOut);
InputComponent->BindAxis("MoveForward", this, &APawnWithCamera::MoveForward);
InputComponent->BindAxis("MoveRight", this, &APawnWithCamera::MoveRight);
InputComponent->BindAxis("CameraPitch", this, &APawnWithCamera::CameraPitch);
InputComponent->BindAxis("CameraYaw", this, &APawnWithCamera::CameraYaw);
}
void APawnWithCamera::MoveForward(float AxisValue)
{
MovementInput.X = FMath::Clamp(AxisValue, -1.f, 1.f);
}
void APawnWithCamera::MoveRight(float AxisValue)
{
MovementInput.Y = FMath::Clamp(AxisValue, -1.f, 1.f);
}
void APawnWithCamera::ZoomIn()
{
bZoomIn = true;
}
void APawnWithCamera::ZoomOut()
{
bZoomIn = false;
}
void APawnWithCamera::CameraPitch(float AxisValue)
{
CameraInput.Y = AxisValue;
}
void APawnWithCamera::CameraYaw(float AxisValue)
{
CameraInput.X = AxisValue;
}