Hello,
Here is what I am trying to achieve:
I want to make a c++ class, which defines my player. I want to be able to add it to my scene through a blueprint based from this class, and to tweak the defaults values written in my c++ file in the blueprint defaults. Currently I can select my static mesh in the defaults through the blueprint editor, but whenever I click on the mesh in the viewport (in game), the editor crashes.
I have got three questions according to my issue:
- Why does it crash?
- Is there a way
to “reinit” the blueprint instead of
deleting it and creating it again when I add
components in the c++ class constructor? - Why is
my compiling so slow when I only add
1 line in my .cpp file? (taking up to 40 seconds atm!)
ABall.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "RollGame.h"
#include "Ball.h"
// Sets default values
ABall::ABall()
{
// 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"));
CameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
CameraSpringArm->AttachTo(RootComponent);
CameraSpringArm->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f,50.0f), FRotator(-60.0f, 0.0f, 0.0f));
CameraSpringArm->TargetArmLength = 400.0f;
CameraSpringArm->bEnableCameraLag = true;
CameraSpringArm->CameraLagSpeed = 3.0f;
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("GameCamera"));
Camera->AttachTo(CameraSpringArm, USpringArmComponent::SocketName);
StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BallMesh"));
StaticMesh->AttachTo(RootComponent);
StaticMesh->SetSimulatePhysics(true);
AutoPossessPlayer = EAutoReceiveInput::Player0;
}
void ABall::PostInitializeComponents()
{
Super::PostInitializeComponents();
}
// Called when the game starts or when spawned
void ABall::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ABall::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
{
}
}
// Called to bind functionality to input
void ABall::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
InputComponent->BindAxis("ForwardAxis", this, &ABall::MoveForward);
InputComponent->BindAxis("RightAxis", this, &ABall::MoveRight);
}
void ABall::MoveForward(float AxisValue){
MovementInput.X = FMath::Clamp<float>(AxisValue, -1.0f, 1.0f);
}
void ABall::MoveRight(float AxisValue){
MovementInput.Y = FMath::Clamp<float>(AxisValue, -1.0f, 1.0f);
}
ABall.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Pawn.h"
#include "Ball.generated.h"
UCLASS()
class ROLLGAME_API ABall : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
ABall();
virtual void PostInitializeComponents() override;
// 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;
protected:
UPROPERTY(EditAnywhere)
USpringArmComponent* CameraSpringArm;
UCameraComponent* Camera;
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly)
UStaticMeshComponent* StaticMesh;
FVector2D MovementInput;
void MoveForward(float AxisValue);
void MoveRight(float AxisValue);
};
Here is the crash report:
"Assertion failed: !bRegistered || AttachParent->AttachChildren.Contains(this) [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.8\Engine\Source\Runtime\Engine\Private\Components\SceneComponent.cpp] [Line: 1335]
Attempt to detach SceneCompon
Ask me if you need more details, or some screens.
Have a nice day!