x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Particle system being garbage collected

I want to spawn explosions when an actor is destroyed. Seems easy, I just give each actor a UParticleSystem* pointer and initialize it in the actor's constructor with whatever explosion I want for that particular actor. When the actor's hitpoints reach zero, I call SpawnEmitterAtLocation() and pass in the UParticleSystem* pointer. The emitter is set to auto-destroy, one loop, etc. Mostly, it appears to work correctly.

Problem is that the particle system sometimes gets garbage collected (I think). I'll have a screen full of explosions and they'll all just periodically disappear. My guess is that the garbage collector runs, sees that the actor that owned the pointer has been destroyed, and cleans it because there are no remaining pointers to it.

I tried a really hacky solution of forcing the actor to hang around for a few seconds before destroying it, but that has worse problems. For one, each type of explosion might have a different duration, and I don't know a way in C++ to get an emitter's duration. For another, doing it this way means I have to play games with making the actor invisible and turning off its collision, etc. Not clean.

Product Version: UE 4.14
Tags:
more ▼

asked Feb 19 '17 at 11:55 PM in C++ Programming

avatar image

Pat-Level17
70 6 10 126

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Why not use the GameplayStatics instead of keeping a pointer to the Particle System Component on each actor? You can rather store a UParticleSystem* (i.e. not Component) reference on your actors and pass that to UGameplayStatics::SpawnEmitterAtLocation(...).

I might be wrong, but I think this uses the emitter pool so you will possibly gain a large performance benefit as well.

more ▼

answered Feb 20 '17 at 01:49 PM

avatar image

staticvoidlol
2.6k 95 40 111

avatar image Pat-Level17 Feb 20 '17 at 05:05 PM

That's how I do it. Here is the call in my actor's code:

 UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), m_explosion_ps, GetActorLocation(), FRotator::ZeroRotator);
 Destroy();

avatar image Pat-Level17 Feb 20 '17 at 06:21 PM

I just found a forum thread where I asked about this nearly two years ago: https://forums.unrealengine.com/showthread.php?73548-Spawn-particle-system-in-Destroyed() There wasn't a solid answer there, but another user mentioned having the same/similar problem.

I think that I may have to resort to having an "explosion actor." Just an empty actor with a particle system component. I believe I can use OnSystemFinished to know when the explosion is done and then Destroy() the actor.

This is a heavy workaround and is going to have a performance cost.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question