DebugGame breaks SkeletalMesh location, but not in Development

I currently have an actor whose root component is a skeletal mesh component:

this->Mesh1P = OI.CreateDefaultSubobject<UWeapon1PMeshComponent>(this, TEXT("First Person Mesh"));
this->RootComponent = this->Mesh1P;

This component simply loads up a skeletal mesh:

UWeapon1PMeshComponent::UWeapon1PMeshComponent(const class FObjectInitializer& OI)
    : Super(OI)
    // Load first person weapon mesh mesh.
    static ConstructorHelpers::FObjectFinder<USkeletalMesh> Weapon1PMesh(TEXT("SkeletalMesh'/Game/Actors/Charger/Models/Charger1stPerson1'"));

    if (Weapon1PMesh.Succeeded())

Now the thing is, the actor works fine in “Development Editor” mode. However, when I try to run the game through Visual Studio with “DebugGame Editor”, the actor’s location is completely wrong, and I cannot change the location at all. As soon as I enter a new location in the editor, it snaps back to some other weird location, as if it picked some random memory location to get the values from. I do not have any debug specific code and I am at loss here what the cause may be and how to fix it.

This does not happen with my static mesh actors, and when I put mesh in a SceneComponent instead and set that as the RootComponent, the SceneComponents is placed nicely where you’d expect it to be. Yet, the skeletesh mesh is again way out of view. The skeletal mesh also does not have any animations. I’ve also checked the logs, and there were no errors whatsoever.



I found the culprit! It was all because of unitialized variables.

I have the following function:

void AWeapon::OnConstruction(const FTransform& Transform)

    // Add additional 1st person model offsets.

this->Settings points to a struct. In this struct however, I have only declared the variables, but not initialized them in the constructor. In C++ this leads to undefined behaviour, as it cannot be guarenteed that the variables will have the value “0”.