A easier, more performant, and designer friendly way to draw the Teleport Trace!

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)…

  1. Delete or comment out all the old code that has to do with the Spline Components.

  2. Migrate over the Niagara systems from the UE VR Template (Mine were called ‘NS_TeleportRing’ and ‘NS_TeleportTrace’), and any of their dependencies.

  3. In your Build.cs file add “Niagara” to your PublicDependencyModuleNames.

  4. Add the components to the class header.

UPROPERTY(VisibleAnywhere)
class UNiagaraComponent* TeleportArc;
UPROPERTY(VisibleAnywhere)
class UNiagaraComponent* DestinationMarker;
  1. 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>
  1. Create them in the constructor.
TeleportArc = CreateDefaultSubobject<UNiagaraComponent>(TEXT("Teleport Arc"));
TeleportArc->SetupAttachment(LeftController);

DestinationMarker = CreateDefaultSubobject<UNiagaraComponent>(TEXT("Destination Marker"));
DestinationMarker->SetupAttachment(GetRootComponent());
  1. Build and Select the components in the BP component outliner and set the ‘Niagara System Asset’ of each to their respective Niagara Systems.

  2. That’s it for the destination marker, you can now show/hide it and set its location like any other component.

  3. 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.

2 Likes

Hi.
This is good that this can be done but also it is useful to know how to do this in C++. I’ve done something similar in the past by lifting the relevant parts for teleport from the VR Template project but The course is showing how you can implement your own solution.

The new VR Template is quite different and I need to find the time to look at it myself. I’d be curious how performant this would be on a device like the quest 2 when not connected to a PC.

Hi,
This way appears a very interesting manner of controlling the teleporter a quite bit better for later usabilities. It’s possible to give us a little bit more details about your solution?
From which lesson in the course did you switch to this approach? Can you share the AVRCharacter.h and AVRCharacter.cpp completely, please?

Privacy & Terms