I have been exploring Unreal with C++ in a toy project, but this issue is driving me insane. For some reason calling either Activate() or Deactivate() on a UParticleSystemComponent crashes the editor.
In an APawn child class header, I have the following declaration:
UPROPERTY(Category = Particle, VisibleDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
class UParticleSystemComponent* EngineFlameL;
The following is a part of the constructor in the corresponding .cpp file:
// Structure to hold one-time initialization
struct FConstructorStatics
{
ConstructorHelpers::FObjectFinderOptional<UStaticMesh> CollisionMesh;
ConstructorHelpers::FObjectFinder<UParticleSystem> EngineFlameL;
FConstructorStatics()
: CollisionMesh(TEXT("/Game/SB/Meshes/fighter/fighter_collider")),
EngineFlameL(TEXT("ParticleSystem'/Game/SB/Particles/P_flame.P_flame'"))
{
}
};
static FConstructorStatics ConstructorStatics;
// Create static mesh components
CollisionMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CollisionMesh0"));
CollisionMesh->SetStaticMesh(ConstructorStatics.CollisionMesh.Get());
RootComponent = CollisionMesh;
// attaching particle systems
EngineFlameL = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("EFL0"));
if (ConstructorStatics.EngineFlameL.Succeeded()) {
EngineFlameL->Template = ConstructorStatics.EngineFlameL.Object;
EngineFlameL->SetupAttachment(CollisionMesh);
EngineFlameL->ActivateSystem(); // This line causes a crash for some reason
}
None of the above variables are referenced anywhere else in the code. Everything works fine when the ActivateSystem() line above is commented out. The particle system is then rendered and fully functional.
If an ActivateSystem() or DeactivateSystem() is called anywhere in the constructor or Tick() functions, compilation will be successful, but the editor will crash as soon as I press the “Play” button. Afterwards, it will also crash instantly upon an attempted (re)start. The editor used to give a crash-report window, but I did not have the required debugging symbols for generating a proper error message. After downloading the symbols, the crash-window does not appear at all anymore.
I can get the project working again after removing the de(activation) calls and recompiling. I have tested this for different particle systems, but the problem persists for all of them.
Am I missing something obvious? Perhaps some kind of initialization? Calling InitializeSystem() first does not seem to help (but does not give issues, so the pointer seems to be valid).
Any help would be hugely appreciated!