Including NiagaraSystem.h: Very weird compile issue?

Hey all, I have a UE5.0 project and I’m trying to play a Niagara particle system from C++. However, the very first step - just adding an include for NiagaraSystem.h - leads to a very weird issue:

NiagaraScript.h(977): [C2666] 'FNiagaraVariable::operator ==': 2 overloads have similar conversions

I’ve tried searching around, but nothing close to the above error unfortunately. In addition, I’ve tried the following:

  • Added “Niagara” to build.cs dependencies. (This is required as get compile issues regarding not finding NiagaraSystem.h)
  • Verified Niagara plugin is enabled (which seems to be on by default in UE5 projects)
  • Made sure no other code is referencing Niagara whatsoever in my project

In addition, here are my included modules at the moment:

PublicDependencyModuleNames.AddRange(new string[]
{
    "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "CableComponent", "AkAudio", "Niagara"
});

The error seems to imply there are multiple conflicting implementations in some way, but can’t find out where they’re coming from. Have been searching around and trying to debug this for a while, but my only guess at the moment is that this is an engine bug- which would be insane given how prevalent Niagara is now yet there’s no searchable instance of this issue at the moment.

Does anyone have any idea on how to get simple Niagara includes to compile? Appreciate any and all help on this issue!


Edit:
Found a hint from this wonderful answer here. In short, if I don’t include any Niagara headers (eg, no explicit NiagaraSystem.h or NiagaraFunctionLibrary.h includes) and use a forward declared class, then the UPROPERTY compiles and works as expected.

For example:

UPROPERTY(EditDefaultsOnly, Category = "Fx Setup")
TMap<RenderEventVFXType, class UNiagaraSystem*> mVFXEventMapping;

However, the moment I try to use any normal Niagara includes in my cpp files (such as #include "NiagaraFunctionLibrary.h" to spawn the system) then I face the same compile issues again.

Need to investigate further. As a side note, adding “Niagara” to build.cs modules is still required.

1 Like

Interestingly enough, the answer is “Forward declare everything Niagara” (currently in UE5.0).

Edit gave an example for a UNiagaraSystem property, but here’s an example on how to forward declare the UNiagaraFunctionLibrary::SpawnSystemAtLocation method.

  1. Include Niagara module in build.cs
  2. Forward declare what you need from Niagara. For example:
// Forward declare UNiagaraFunctionLibrary method and all relevant elements as necessary
enum class ENCPoolMethod : uint8 // Yes this is necessary to forward declare with values unfortunately... Syntax dictates that this must match original definition (NiagaraCommon.h)
{
    None, AutoRelease, ManualRelease, ManualRelease_OnComplete, FreeInPool,
};
class UNiagaraComponent;
class UNiagaraFunctionLibrary {
  public:
    static UNiagaraComponent* SpawnSystemAtLocation(const UObject* WorldContextObject, class UNiagaraSystem* SystemTemplate, FVector Location, FRotator Rotation = FRotator::ZeroRotator, FVector Scale = FVector(1.f), bool bAutoDestroy = true, bool bAutoActivate = true, ENCPoolMethod PoolingMethod = ENCPoolMethod::None, bool bPreCullCheck = true);
};
  1. Finally use your Niagara classes and/or methods as you would normally. Eg:
UNiagaraFunctionLibrary::SpawnSystemAtLocation(
  mWorldRef.Get(), particleSystemToSpawn, location, rotation, defaultScale, autoDestroy, autoActivate,
  ENCPoolMethod::AutoRelease, doPrecullCheck
);

Hoping the underlying issue gets fixed in UE5.1 so we no longer need to awkwardly forward declare everything Niagara in C++.

3 Likes

For me, this exact error occurred. I “cleaned” my project, i.e.

  • deleted folders .vs, binaries, saved, intermediate, deriveddatacached
  • deleted the .sln file
  • recreated the project files
  • recompiled

and the error is gone and I can use the includes instead of forward declaration just fine.

1 Like