referencing a UParticleSystemComponent in code


How does one reference a UParticleSystemComponent in code?

When I try creating a property that would hold it:

UPROPERTY( VisibleDefaultsOnly, Category = Effects )
      TSubobjectPtr<UParticleSystemComponent>       ShotFX;

and then initialize it in the constructor:

// particle system effect
   ShotFX = PCIP.CreateDefaultSubobject<UParticleSystemComponent>( this, TEXT( "ShotFX" ) );
   ShotFX->AttachParent = ShotgunMesh;

I get a compile time error saying that the class is undefined:

Any attempt to include its header tells me that the file is off limits.


Nevermind - found it.
Although it’s kind of weird that you get a StaticMeshComponent included out of the box, and in order to get a particle system component, you need to add these:

#include "ParticleHelper.h"
#include "Particles/ParticleSystem.h"
#include "Particles/ParticleSystemComponent.h"


The same thing happens with UDecalComponent. I posted a question on answerhub about this. I wonder if this is by design or simply an oversight.

I would say that is a philosophy change that has emerged over time, particularly with the removal of UnrealScript.

The problem with putting everything in Engine.h is that when you change something you have to recompile everything and your compile times get much worse. Ideally each cpp would include just the headers that it needs and it might improve compile times. Sometimes there are dependencies that must be grouped together which is where things like ParticleDefinitions.h and SoundDefinitions.h come from. And for the rest of it is a legacy issue, it takes a long time to clean up the reliance on the global header includes and we have to balance the time it would take and issues it would introduce for users of the engine when getting new versions against the benefits it will bring us.

MSDN handles this well: for each Win32 function or data structure, there’s a note at the bottom telling you which header file it’s actually defined in, and which header you want to include. It’d be nice to have that in the API docs for each class.

That would be quite nice, I agree. I found, that there are some Engine*Classes.h files that can be used. EngineDecalClasses.h for instance includes DecalActor and DecalComponent.