Im trying to spawn a niagara system in cpp. I didnt find many examples online, but so far i could put this together:
It compiles but when i try it the arrows are nowhere to be seen. What am i doing wrong?
The niagara system works if i just throw it in the world in the editor
But not if im spawning it from my actor.
If needed i can post videos.
\h:
#pragma once
#include "CoreMinimal.h"
#include "MainBat.h"
#include "Components/SceneComponent.h"
#include "NiagaraFunctionLibrary.h"
#include "NiagaraComponent.h"
#include "ArcherBat.generated.h"
UCLASS()
class K2K_TEST_CPP_API AArcherBat : public AMainBat
{
GENERATED_BODY()
public:
AArcherBat();
virtual void BeginPlay() override;
class UNiagaraSystem* ArrowsNiagara;
USceneComponent* NiagaraSceneComp;
class UNiagaraComponent* NiagaraComp;
};
\cpp:
#include "ArcherBat.h"
AArcherBat::AArcherBat()
{
}
void AArcherBat::BeginPlay()
{
Super::BeginPlay();
FString NiagaraPath = "/Game/TopDownBP/Archer/niagara_arrow/NS_Arrow.NS_Arrow";
ArrowsNiagara = Cast<UNiagaraSystem>(StaticLoadObject(UNiagaraSystem::StaticClass(), nullptr, *NiagaraPath));
NiagaraComp = UNiagaraFunctionLibrary::SpawnSystemAttached(ArrowsNiagara, NiagaraSceneComp, NAME_None, FVector(0.f,0.f,400.f), FRotator(0.f), EAttachLocation::Type::KeepRelativeOffset, true);
}