Object Constructor Only Called When Debugging

Chris McCole
Mon, 10 Aug 2020 01:52:54 +0000
C++

Hello, I am trying to setup my FPSCharacter in C++ and I am creating the components and assigning them in the cpp constructor. Upon building my code, everything compiles successfully. However, once I open the editor and hit play the expected behaviour does not run as expected.

This is odd, as if I run the game with debugging on, it opens up the editor in debug mode and once I hit play in this debug editor, the game starts up and the constructor clearly runs and executes properly. I will say that an exception is thrown that a breakpoint was triggered on a line in my constructor, when I don’t have a breakpoint on that line; This occurs when the engine is opening.

I will say that in the normal editor, my input bindings work properly, but the constructor does not seem to run, and in the debug editor the constructor runs, but the input bindings do not bind properly.

Here is my constructor:

AFpsCharacter::AFpsCharacter()
{
 	// 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;

	fpsCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FPS Camera"));

	mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("FPS Skeletal Mesh"));
	mesh1P->AttachToComponent(fpsCamera, FAttachmentTransformRules::SnapToTargetNotIncludingScale);

	static ConstructorHelpers::FObjectFinder<USkeletalMesh> armsSkeletonAsset(TEXT("/Game/_ZombiesClone/Player/ownerView/Arms/FPSArms_rigged"));

	if (armsSkeletonAsset.Succeeded())
	{
		mesh1P->SetSkeletalMesh(armsSkeletonAsset.Object);
		mesh1P->SkeletalMesh = armsSkeletonAsset.Object;
	}

	GetMesh()->bOwnerNoSee = true;
	mesh1P->bOnlyOwnerSee = true;
}

The result in editor:

The result in DebugGame Editor:

2 posts - 1 participant