Niagara SpawnSystemAttached not registered to actor

Hi, I just found the niagara components spawn with SpawnSystemAttached is not registered with Actor, e.g we cannot retrieve it with GetComponent , is this a design choice or bug?

Hi,

Hope you’re doing great.

It’s a design choice.

SpawnSystemAttached creates and registers the niagara component with the world, so it appears and ticks like any other component, but it’s not added to the actor’s components array. That’s why GetComponentByClass or GetComponents won’t find it.

In case you need track your loop VFX, you have some options:

  1. Create the Niagara component as a subobject of your AActor and manually activate/deactivate it when needed;
  2. Store the returned component pointer as a raw pointer or a TWeakObjectPtr marked with UPROPERTY for lifetime safety;
  3. If you’re spawning many effects, store them in a TArray, which lets you manage and destroy them when needed.

Depending on your implementation, you can also take advantage of the ENCPoolMethod parameter in the overridden SpawnSystemAttached function.

Hope this helps - take care!

I looked through source code, the pool must be none for it to attach. If it is not none, it is attached to global world pool. It should spawn an warning/error.

So I presume the best way to manager your pool is using TArray's, maybe this may achieve what you’re trying to accomplish.