Understanding hierachy in a BP

Hello !
I did a simple change to the third person character and see how I could reference additional
particles components.
So I just drop 2 particles effects in my base class (don’t want them to be spawned on the fly)
image
On begin play, I’d like to find my particles and store them in a UParticleSystemComponent*
to active them when needed.
Does anyone would know how to do that ?
I give them tags to identify them but all I did to find them is unsuccessfull for now…
GetOwner()->Children[0]->GetComponents() give me a bunch of UActorsComponents
but none of them is a particle effect…
It seems that parenting does not match what is displayed on the interface.
TBH I’m a bit lost any help would be welcome ^^

Hi RealBastorama,

One way is to create a “Scene” component and add the particles to that, then you can just enumerate the scenes children:

image

Another approach would be to not put them in the component list of the BP at all, but instead to list them in your .h file where they can be set in the BP like:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Engine Flares")
UNiagaraSystem* EngineFlaresNiagara;

Then you can reference them to spawn and control them like:

UNiagaraComponent* ThisFlare=UNiagaraFunctionLibrary::SpawnSystemAttached(EngineFlaresNiagara,SomeMeshReference,FName(*SocketBase),FVector::ZeroVector,FRotator::ZeroRotator,EAttachLocation::SnapToTarget,false,true);

At that point you can reference them with ThisFlare (in my case) and do what ever you need to do with the emitter. In my case, I make it larger or smaller depending on engine speed.

Should be able to work with them from Blueprint too at that point if ThisFlare were another component pointer (blueprintreadwrite) in your .h file.

The way I’m spawning it here means adding a socket to what you want them connected to.

Hello RecourseDesign & eagletree !

@eagletree, for the main character, I tend to use more “statically created objects”. Less stress on the spawning system is good as I know that I’ll need the objects everytime… I also notice lags, about 3 frames and a few more on the first spawn which was noticable on VFX…
On different topics (such as for breakables) I would probably use the same approach you mentionned.

@RecourseDesign, I did add a scene with the 2 particles effects and… surprise. It does not affect the number of components I could get from the main character (still 11, no particles nor scene component). BUT… I added a small class called VFXHolder (that’s also an elegant way to get that out of character responsabilities), when I get the number of components from his father during BeginPlay, I have 13 components, 2 are particles components and a scene component… (one of them vanished)

As a conclusion, I think that object creation order make the scene being created later as for the particles and the VFXHolder class.

For the issue I had, the solution is quite good and even better/more scalable than my first idea. Splitting responsabilities on the main character is often a good choice…

Thanks you guys for the help !!! :slight_smile:

A few additional pictures showing the issue :

1 Like

I think I see more what you are talking about. You are getting components and then specifying a subclass of only child actor components. I have to iterate through SceneComponents in nearly every actor I have. I ask for the specific class and iterate through that checking the name, so for example, with scenecomponents, I’ll do:

    GetComponents<USceneComponent>(sccomps);

Then iterate through the sccomps returns and get the scenecomponents I’m interested in by looking at the GetName() for each and the unique fragment that identifies my components. You could do the same for the Niagara class you’re looking for. I may be missing something but you are asking for ChildActorComponents and your stuff won’t be in that group. So wouldn’t you want just a

GetComponents<UNiagaraComponent>(NiagaraComps);

or whatever the API says your system component class is?