# Beam particle system randomly disappears

**URL:** <https://forums.unrealengine.com/t/beam-particle-system-randomly-disappears/28699>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [April 28, 2015, 9:41pm UTC](https://forums.unrealengine.com/t/beam-particle-system-randomly-disappears/28699 "2015-04-28T21:41:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_1c4cdb3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1c4cdb3c](https://forums.unrealengine.com/u/anonymous_user_1c4cdb3c)\
**Post date:** [April 28, 2015, 9:41pm UTC](https://forums.unrealengine.com/t/beam-particle-system-randomly-disappears/28699/1 "2015-04-28T21:41:07Z")

</div>

Hi,

I have a beam particle system, and a beam particle system component that I create from it, like so:

```auto

    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:

1. I set the beam to visible with m\_beam\_ps-\>SetVisibility(true).
2. 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:

```auto

    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?

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 28, 2015, 11:44pm UTC](https://forums.unrealengine.com/t/beam-particle-system-randomly-disappears/28699/2 "2015-04-28T23:44:56Z")

</div>

**Garbage Collection Protection**

When you create your Beam PSC, make sure to store it in a global **UPROPERTY()** variable!

//.h file

```auto

UPROPERTY()
UParticleSystemComponent* m_beam_ps;

```

Otherwise your particle is getting **garbage collected**!

I have a wiki on UE4 Garbage Colleciton Here:

**Memory Management and GC in UE4**

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

🙂

Rama

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1c4cdb3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1c4cdb3c](https://forums.unrealengine.com/u/anonymous_user_1c4cdb3c)\
**Post date:** [April 29, 2015, 8:22pm UTC](https://forums.unrealengine.com/t/beam-particle-system-randomly-disappears/28699/3 "2015-04-29T20:22:04Z")

</div>

That’s really helpful. Thanks Rama.

I have to say that it’s a little aggressive for the engine to garbage collect something that’s still in use, though. I thought that garbage collection was for memory that has gone out of scope. I guess UE cheats a little to improve performance.
