How to invoke a UNiagaraComponent in C++? Question

Hello guys!

I was trying to use a UNiagaraComponent reference on my code, and I wrote the following script in the Build.cs:

// Copyright Epic Games, Inc. All Rights Reserved.
// Copyright Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

public class PRJ_ProjectileTest : ModuleRules
public PRJ_ProjectileTest(ReadOnlyTargetRules Target) : base(Target)
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

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

PublicIncludePaths.AddRange(new string] {
Path.Combine(ModuleDirectory, "Niagara")



#include "Niagara/Public/NiagaraComponent.h"


#include "Engine/Plugins/FX/Niagara/Source/Niagara/Public/NiagaraComponent.h"

But it doesn’t work? Why? What’s is the proper way to do it?


Just a bump

I was having the same problem myself for a while. Here’s how I did it:

in ProjectName.cs file:

new string]

And in ProjectName.uproject file:

“FileVersion”: 3,
“EngineAssociation”: “4.25”,
“Category”: “”,
“Description”: “”,
“Name”: “BCGm”,
“Type”: “Runtime”,
“LoadingPhase”: “Default”,

Not sure if it’s the correct way, but it worked for me.

Thanks, I’ll try! :slight_smile:

You have an error in your .cs file:
“new string]”->There’s a missing “[”
And you have to add “using System.IO” at the top of your file.

I’ve fixed this, but I still can’t include Niagara. Does anyone know how to solve this?
I’ve tried:
#include “Niagara/Public/NiagaraComponent.h”
#include “Niagara/NiagaraComponent.h”

I got this to work but I don’t know if I’m convinced.
I add this to my build.cs:

PublicIncludePaths.AddRange(new string[] {Path.Combine(EngineDirectory, "PlugIns/FX/Niagara/Source") });

By chance I tried “EngineDirectory” and it worked :D.
To include the files I had to:

#include "Niagara/Classes/NiagaraSystem.h"
#include "Niagara/Public/NiagaraFunctionLibrary.h" 

Have no idea why some files are under “classes” and other under “public”.

Surprisingly I didn’t find many pages in google about including plugins headers. The official documentation is also sparse.

And I still get errors, but the code compiles.

My Niagara effect is working but I still get this errors:


Anyone knows why?