Custom C++ component with Niagra particle system pointers -- blueprint class keeps resetting them to null.

I have a C++ component that I’ve created which has two Niagra particle system pointers:

UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class ZOMBIETOWN_API UGunComponent : public UActorComponent
{
// ** usual stuff here, begin play so on..
public:
 // ** other properties here...

// Properties I'm having trouble with below...
	UPROPERTY(BlueprintReadWrite, EditAnywhere)
		UNiagaraSystem* MuzzleFlashParticles = nullptr;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
		UNiagaraSystem* HitParticles = nullptr;
};

I find that I can set “HitParticles” and “MuzzleFlashParticles” in the editor when I make a blueprint class inheriting from AActor and attaching a UGunComponent to it, as desired. But when I save the project, save the blueprint class, close the editor and re-open, I find that those variables get reset to null again!

I find that when I change the particle systems in the editor and save, the uasset file for the blueprint class changes. The diff looks like a couple of bytes. So it looks like maybe it’s not being reloaded?
bp_gun_blueprint
policegun

Edit: I tried DUPLICATING this blueprint class, and the duplicate works as expected – I can save an reload the particles. So for now, I have a workaround, but I have no idea why the original keeps resetting?

Depends on your goals, but:
1. UNiagaraSystem* pointers are used to store already spawned objects. So it’s more a runtime thing.
2. Likely the thing you need is an TSubclassOf<UNiagaraSystem>, which will let you select a class to use in your blueprint

1 Like

Hmm, according to this tutorial; Using Niagara in C++ | Community tutorial

It looks like I should be using a UNiagraSystem* as a UPROPERTY to later spawn it? I could try TSubclassOf, but I thought that was for spawning instances of actors and the like.

Seems i was wrong.

TSubclassOf<> is a default solution for other cases, and if you using pointer instead of it, the symptoms will be just like you described it.

But in case of UNiagaraSystem it’s seems have to be pointer instead. I didn’t delve into this, so i can’t answer this one, sorry. In my project it works with pointer and i don’t experience such problem