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:
private:
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 of the atmosphere. I’ve attached it to this blueprint, and can compile ONE time. The game will run fine in the editor, and excuse as expected. BUT, if I try to compile the BP a second time 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 occurring, and what I should do to fix it?