CreateDefaultSubobject Crashes the editor.

Hi, I want to declare my components in C++ so I can edit them there, but every time I compile, It crashes. Here is my .h:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

include “CoreMinimal.h”
include “InputActionValue.h”
include “GameFramework/Pawn.h”
include “Character.generated.h”

class UCapsuleComponent;
class ALever;
class USpringArmComponent;
class UCameraComponent;
struct FInputActionValue;
class UInputAction;
class UInputMappingContext;
UCLASS()
class FNAFTSOR_API ACharacter : public APawn
{
GENERATED_BODY()

public:
// Sets default values for this pawn’s properties
ACharacter();

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

// The Inout Mapping Context
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Input")
UInputMappingContext* MappingContext;
// Input Action for Looking
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Input")
UInputAction* LookAction;
// Input Action for CLicking
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Input")
UInputAction* ClickAction;

// Input Functions
void Look(const FInputActionValue& Value);
void Click(const FInputActionValue& Value);

public:
// Called every frame
virtual void Tick(float DeltaTime) override;

// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

// Teleports and Rotates the Camera
UFUNCTION(BlueprintCallable)
const void SetCameraLocation(FVector NewLocation);

private:
// Determines How Far the LineTrace Reaches
FVector Reach;

// The Components in the Blueprint
UPROPERTY(EditAnywhere)
UCapsuleComponent* CapsuleComponent;
UPROPERTY(EditAnywhere)
USpringArmComponent* SpringArmComponent;
UPROPERTY(EditAnywhere)
UCameraComponent* CameraComponent;
	
// How Fast the Character Rotates
UPROPERTY(EditAnywhere)
float RotationInterpSpeed = 5;

// Sets to true if the A or D keys are pressed
bool bIsInterpolating;

// Array of the Locations the Player is able to look
UPROPERTY(EditAnywhere)
TArray<FRotator> TargetRotations;
int32 CurrentTargetIndex;

// Camrea Screen Widget
UPROPERTY(EditAnywhere, Category="UI")
TSubclassOf<UUserWidget> CamreaScreenClass;

My Constructer:

// 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;

CapsuleComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT("Capsule Component"));
RootComponent = CapsuleComponent;

SpringArmComponent = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
SpringArmComponent->SetupAttachment(RootComponent);

CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("Camrea Component"));
CameraComponent->SetupAttachment(SpringArmComponent);

Here is the dump:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION 0x00000080248c8b44

UnrealEditor_Test_patch_0!ACharacter::ACharacter() [C:\Users\Askari\Documents\Unreal Projects\Fnaf-TOSR\Source\Fnaftsor\Character.cpp:22]
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_LiveCoding
UnrealEditor_LiveCoding
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
kernel32
ntdll

Turns out, by removing the RootComponent = CapsuleComponent did the trick!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.