I have a beam particle system, and a beam particle system component that I create from it, like so:
static ConstructorHelpers::FObjectFinder<UParticleSystem> beam_finder(TEXT("ParticleSystem'/Game/Particles/beam.beam'")); m_beam_ps = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("beam_ps")); m_beam_ps->SetTemplate(beam_finder.Object); m_beam_ps->SetRelativeLocation(FVector(24.889f, 0.0f, 11.943f)); m_beam_ps->AttachTo(RootComponent); m_beam_ps->SetVisibility(false);
I’m using it as a weapon effect, so, in the editor, the source of the beam is set to “Emitter” and the target is set to “User Set.” When the player presses the fire button, the following happens:
- I set the beam to visible with m_beam_ps->SetVisibility(true).
- I do a line trace to see if it hit anything.
3a) If it does hit something, I set the beam’s target point to whatever it hit.
3b) If it didn’t hit anything, I set the target to a point off screen so the beam appears to just shoot out into space.
When the player releases the fire button, I just hide the beam again with m_beam_ps->SetVisibility(false).
This all works just fine, for a while, but the beam eventually just disappears. Calling SetVisibility(true) just won’t bring it back. I checked these:
if (!m_beam_ps->IsVisible()) PRINTF(TEXT("not visible")); if (!m_beam_ps->IsActive()) PRINTF(TEXT("not active"));
And they’re both returning true while firing (neither message is ever printed).
Any idea why the particle system is disappearing?