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"

Spring Arm and Camera attachment

I am trying to add spring arm and camera to a basic pawn. When I put the bp_pawn in map and hit play it crashes the editor.

 // Fill out your copyright notice in the Description page of Project Settings.
 #include "SCharacter.h"
 #include "Engine/World.h"
 #include "Components/InputComponent.h"
 #include "GameFramework/SpringArmComponent.h"
 #include "Camera/CameraComponent.h"
 // Sets default values
      // 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;
 // Called when the game starts or when spawned
 void ASCharacter::BeginPlay()
     RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
     SpringArmComp = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComp"));
     SpringArmComp->bUsePawnControlRotation = true;
     CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComp"));
     AutoPossessPlayer = EAutoReceiveInput::Player0;
 // Called every frame
 void ASCharacter::Tick(float DeltaTime)
 void ASCharacter::MoveSideToSide(float value)
     AddMovementInput(GetActorRightVector() * value);
 void ASCharacter::MoveForward(float value) 
     AddMovementInput(GetActorForwardVector() * value);
 // Called to bind functionality to input
 void ASCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
     PlayerInputComponent->BindAxis("MoveForward", this, &ASCharacter::MoveForward);
     PlayerInputComponent->BindAxis("MoveSideToSide", this, &ASCharacter::MoveSideToSide);
     PlayerInputComponent->BindAxis("LookUP", this, &ASCharacter::AddControllerPitchInput);
     PlayerInputComponent->BindAxis("Turn", this, &ASCharacter::AddControllerYawInput);
 // Fill out your copyright notice in the Description page of Project Settings.
 #pragma once
 #include "CoreMinimal.h"
 #include "GameFramework/Character.h"
 #include "SCharacter.generated.h"
 class UCameraComponent;
 class USpringArmComponent;
 class COOPGAME_API ASCharacter : public ACharacter
     // Sets default values for this character's properties
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
     void MoveForward(float value);
     void MoveSideToSide(float value);
     UPROPERTY(EditAnywhere,BlueprintReadOnly, Category = "Components")
     UCameraComponent* CameraComp;
     UPROPERTY(EditAnywhere,BlueprintReadOnly,Category = "Components")
     USpringArmComponent* SpringArmComp;
     // Called every frame
     virtual void Tick(float DeltaTime) override;
     // Called to bind functionality to input
     virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
Product Version: UE 4.21
more ▼

asked Feb 20 '19 at 01:32 PM in C++ Programming

avatar image

1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You shouldn't use "CreateDefaultSubobject" outside of a constructor. Use "NewObject" instead.

See https://answers.unrealengine.com/questions/317148/newobject-or-createdefaultsubobject.html.

more ▼

answered Feb 21 '19 at 01:54 PM

avatar image

2.6k 95 41 111

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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