I’ve got an atmosphere class that contains pointer to World Light, Atmosphere Fog, Exponential Height Fog and Audio Component:
header:
UPROPERTY(EditAnywhere) UDirectionalLightComponent* WorldLight = nullptr;
UPROPERTY(EditAnywhere) UAtmosphericFogComponent* AtmosphereFog = nullptr;
UPROPERTY(EditAnywhere) UExponentialHeightFogComponent* HeightFog = nullptr;
UPROPERTY(EditAnywhere) UAudioComponent* AmbientSound = nullptr;
cpp:
AAtmosphere::AAtmosphere()
{
PrimaryActorTick.bCanEverTick = false;
AmbientSound = CreateDefaultSubobject<UAudioComponent>(FName(TEXT("Ambient Sound")));
WorldLight = CreateDefaultSubobject<UDirectionalLightComponent>(FName(TEXT("World Light")));
AtmosphereFog = CreateDefaultSubobject<UAtmosphericFogComponent>(FName(TEXT("Atmosphere Fog")));
HeightFog = CreateDefaultSubobject<UExponentialHeightFogComponent>(FName(TEXT("Height Fog")));;
}
This class is used as a child to my AtomsphereController class.
header:
UPROPERTY(EditAnywhere) AAtmosphere* Atmosphere = nullptr;
APlayerController* MyController = nullptr;
cpp:
AtmosphereController::UAtmosphereController()
{
bWantsBeginPlay = true;
PrimaryComponentTick.bCanEverTick = false;
Atmosphere = CreateDefaultSubobject<AAtmosphere>(FName(TEXT("Atmosphere")));
}
Now, this AtmosphereController is attached to an actor in my game that is suppose to have control over the atmosphere. If I attach it to this blueprint, I can safely compile ONE time. At this point, the game will run fine in the editor (PIE), and execute as expected. BUT, if I try to compile the BP a second time (no changes, just a mere click of the Compile button) or delete the AtmosphereController from the BP… insta-crash. I know it has something to do with the AtmosphereController’s call to CreateDefaultSubobject, because I can comment it out, recompile the game, and then delete it from my BP. But once I uncomment, and recompile my BP for a second time, it starts crashing again.
Can someone explain WHY this is causing such an awkward side effect?