x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

UE Crashes on startup

Hello.
I recently started C++ in UE.
I created class DefaultPlayer. I added few components and a simple movement. When I compiled this class UE crashed. Now it crashes every time I enter this project, making it unusable.
Here's my DefaultPlayer.h:

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #pragma once
 
 #include "GameFramework/Pawn.h"
 #include "DefaultPlayer.generated.h"
 
 UCLASS()
 class UNREALISAAC_API ADefaultPlayer : public APawn
 {
     GENERATED_BODY()
 
 public:
     // Sets default values for this pawn's properties
     ADefaultPlayer();
 
     // 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;
 
     // Movement
     FVector2D MovementInput;
     FVector2D RotationInput;
     void MoveForward(float AxisValue);
     void MoveRight(float AxisValue);
 
     // Components
     UPROPERTY(EditAnywhere)
     UShapeComponent* PlayerCollision;
     UCameraComponent* PlayerCamera;
 
     
     
 };
 

And DefaultPlayer.cpp:

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "UnrealIsaac.h"
 #include "DefaultPlayer.h"
 
 
 // Sets default values
 ADefaultPlayer::ADefaultPlayer()
 {
      // 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;
 
     PlayerCollision->CreateDefaultSubobject<UCapsuleComponent>(TEXT("PlayerCollision"));
     RootComponent = PlayerCollision;
     PlayerCamera->CreateDefaultSubobject<UCameraComponent>(TEXT("PlayerCamera"));
     PlayerCamera->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f));
     PlayerCamera->bUsePawnControlRotation = true;
 
 }
 
 // Called when the game starts or when spawned
 void ADefaultPlayer::BeginPlay()
 {
     Super::BeginPlay();
     
 }
 
 // Called every frame
 void ADefaultPlayer::Tick( float DeltaTime )
 {
     Super::Tick( DeltaTime );
 
     MovementInput = MovementInput.GetSafeNormal() * 500.0f;
     FVector NewLocation = GetActorLocation();
     NewLocation += GetActorForwardVector() * MovementInput.X * DeltaTime;
     NewLocation += GetActorRightVector() * MovementInput.Y * DeltaTime;
     SetActorLocation(NewLocation);
 
 }
 
 // Called to bind functionality to input
 void ADefaultPlayer::SetupPlayerInputComponent(class UInputComponent* InputComponent)
 {
     Super::SetupPlayerInputComponent(InputComponent);
 
     InputComponent->BindAxis("W-S", this, &ADefaultPlayer::MoveForward);
     InputComponent->BindAxis("A-D", this, &ADefaultPlayer::MoveRight);
 
 }
 
 // Movement
 
 void ADefaultPlayer::MoveForward(float AxisValue)
 {
     MovementInput.X = FMath::Clamp<float>(AxisValue, -1.0f, 1.0f);
 }
 
 void ADefaultPlayer::MoveRight(float AxisValue)
 {
     MovementInput.Y = FMath::Clamp<float>(AxisValue, -1.0f, 1.0f);
 }
 


It's 3rd project I've lost because of this. What am I doing wrong?
Please help me.

Product Version: UE 4.14
Tags:
more ▼

asked Jan 15 '17 at 03:03 PM in C++ Programming

avatar image

J0K3R_12QQ
94 21 24 28

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

It is

 PlayerCollision = CreateDefaultSubobject(TEXT("PlayerCollision"));
 ...
 PlayerCamera = CreateDefaultSubobject(TEXT("PlayerCamera"));

and not

 PlayerCollision->CreateDefaultSubobject(TEXT("PlayerCollision"));
 ...
 PlayerCamera->CreateDefaultSubobject(TEXT("PlayerCamera"));

I am pretty sure this is the crash because you are accessing an uninitialized object. You should be able to tell the problem from the crash log. It will output which file and line it crashed in. With that info you can debug your stuff faster!

Cheers, Kishore

more ▼

answered Jan 15 '17 at 07:07 PM

avatar image

kishoreven
302 13 13 25

avatar image J0K3R_12QQ Jan 16 '17 at 03:27 PM

Thank you!

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question