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 material garbage collected

Hello,

There has been a very annoying bug in the packaged version of my game where it would occasionally crash due to random particle system component related code. Today I luckily ran into the crash while debugging (DebugGame config) and got a helpful crash log. The output informed me that a material of a particle system required module was invalid.

So I figured the reason for this must be that the material is garbage collected for some reason. I am dynamically loading the particle system during the game with this code:

  // Some code
  static UParticleSystem * ExplosionEmitter = UBrickGameInstance::SynchronousLoad<UParticleSystem>("ParticleSystem'/Game/BrickRigs/ParticleFX/Fire/P_Explosion.P_Explosion'");

Loading function:

  template<>
         inline UParticleSystem * UBrickGameInstance::SynchronousLoad(const FString & AssetPath)
         {
             // Inside the loading function
             UParticleSystem * ParticleSystem = LoadObject<UParticleSystem>(NULL, *AssetPath);
                 if (ParticleSystem)
                 {
                     ParticleSystem->AddToRoot();
             }
     
     return ParticleSystem;
     }

So I added this code as a workaround and it seems to have fixed the issue:

 for (UParticleEmitter * Emitter : ParticleSystem->Emitters)
         {
             for (UParticleLODLevel * LODLevel : Emitter->LODLevels)
             {
                 if (LODLevel->RequiredModule->Material)
                 {
                     LODLevel->RequiredModule->Material->AddToRoot();
                 }
             }
         }

Although the workaround seems to be working, it's not a nice solution so I would be glad to hear the reason why it didn't not work in the first place. Am I missing something? Shouldn't it be enough to add the particle system to the root?

Product Version: UE 4.13
Tags:
more ▼

asked Nov 27 '16 at 08:03 PM in C++ Programming

avatar image

Fluppi393
457 35 33 54

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hey Fluppi,

Could it be that it gets collected as garbage because your particle system does not have an outer when it gets created? LoadObject(NULL, *AssetPath);

Maybe if you put the outer to the right UWorld it will not get collected as garbage. I also ran into similar problems like this and was able to solve it this way.

Hope this helps :)
Elias

more ▼

answered Nov 28 '16 at 11:34 AM

avatar image

PasteDog
1.2k 24 16 53

avatar image Fluppi393 Nov 28 '16 at 02:29 PM

Thanks for the response. Maybe it would prevent the material from being garbage collected if the particle system had an outer object, but that doesn't really work in my code since all my LoadObject calls are static, i.e. I cannot use the world or an actor or component as outer since they could be deleted until the next time the particle system is needed. AddToRoot is supposed to prevent any object from being garbage collected, which also works in all other cases. I based my code on ConstructorHelpers::FObjectFinder, which uses these exact lines:

 T* ObjectPtr = LoadObject<T>(NULL, *PathName);
         if (ObjectPtr)
         {
             ObjectPtr->AddToRoot();
         }
avatar image PasteDog Nov 28 '16 at 03:14 PM

Ah ok I see,
have you tried setting the particle system and materials as UPROPERTY's? I actually just had also a problem where something got deleted and by setting the array to uproperty it stopped happening. Not sure if it will help you :)

avatar image Fluppi393 Nov 28 '16 at 05:41 PM

Yes very likely that would also prevent the crash, at least I never experienced an object being garbage collected from a UPROPERTY. However in some cases this is not really a nice solution, for example when I want to spawn a generic explosion from a static function where I don't have a place to store UPROPERTY's.

I guess the question is not really about finding a workaround, since I already have one for this specific case. I would rather like to know why this happened in the first place, and if it is a bug or meant to be like this?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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