So while looking around the Unreal VR Blueprint template I saw they had a few Niagara systems for both the Destination Marker and the Teleport Arc. So I decided to see if I could get them both to work with my code. Here’s how I did it (As of UE4.27.2)…
-
Delete or comment out all the old code that has to do with the Spline Components.
-
Migrate over the Niagara systems from the UE VR Template (Mine were called ‘NS_TeleportRing’ and ‘NS_TeleportTrace’), and any of their dependencies.
-
In your Build.cs file add “Niagara” to your PublicDependencyModuleNames.
-
Add the components to the class header.
UPROPERTY(VisibleAnywhere)
class UNiagaraComponent* TeleportArc;
UPROPERTY(VisibleAnywhere)
class UNiagaraComponent* DestinationMarker;
- Add the needed includes to the cpp file. (The 2nd one is for a function that we’ll use later)
#include <../Plugins/FX/Niagara/Source/Niagara/Public/NiagaraComponent.h>
#include <NiagaraDataInterfaceArrayFunctionLibrary.h>
- Create them in the constructor.
TeleportArc = CreateDefaultSubobject<UNiagaraComponent>(TEXT("Teleport Arc"));
TeleportArc->SetupAttachment(LeftController);
DestinationMarker = CreateDefaultSubobject<UNiagaraComponent>(TEXT("Destination Marker"));
DestinationMarker->SetupAttachment(GetRootComponent());
-
Build and Select the components in the BP component outliner and set the ‘Niagara System Asset’ of each to their respective Niagara Systems.
-
That’s it for the destination marker, you can now show/hide it and set its location like any other component.
-
As for the NS_TeleportTrace, it had a User Defined Vector array that you need to populate for it to work correctly. This code is how you can do it in C++, thus drawing the Arc. (Assuming that the Parameter name is still “PointArray”, you can double check this in NS_TeleportTrace’s user Parameter’s tab)
void AVRCharacter::DrawTeleportArc(const TArray<FPredictProjectilePathPointData>& PathData)
{
if (TeleportArc == nullptr) return;
TArray<FVector> Points;
for (const FPredictProjectilePathPointData& Point : PathData)
{
Points.Add(Point.Location);
}
UNiagaraDataInterfaceArrayFunctionLibrary::SetNiagaraArrayVector(TeleportArc, TEXT("PointArray"), Points);
}
And there you go. You can now show/hide the beam how ever you like. You can modify the beam in the Niagara system editor, and you don’t have to worry about managing a bunch of meshes/objects. Also makes the code much more readable.