C++
Lines Plus for Unreal · C++
Every node of the plugin is also a C++ function with the same name and the same parameters. This chapter gives the names that you need and some examples.
Setup
Add LinesPlus to the dependency modules of your module in its Build.cs file:
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "LinesPlus" });
Headers and classes
| Header | Contents |
|---|---|
| LinesPlusLibrary.h | ULinesPlusLibrary, with the nodes as static functions. The header lists every function with its parameters and their default values. |
| LinesPlusComponent.h | ULinesPlusComponent, the component that draws one line, and ALinesPlusActor, the line actor. The component of the actor is its member Line. |
| LinesPlusTypes.h | FLinesPlusStyle, the look of a line. FLinesPlusHandle, the value that a draw function returns. ULinesPlusStyleAsset, the style asset, with its member Style. The other headers include this one. |
Names
- A function has the name of its node without spaces: Draw Line is DrawLine.
- The first parameter of the functions of the library is an object of the world, usually this.
- The values that a node returns in extra pins are reference parameters of the function, for example the hit of DrawTrajectory and the line and the point of the find functions.
- A setting has its name without spaces: End Width Scale is EndWidthScale. A setting that is on or off starts with a b: bLit, bCastShadow, bUseEndColor, bVisibleThroughWalls, bUseHiddenColor, bSnapToGround, and bClosed, bSmooth and bDrawOnBeginPlay in the component. X-Ray is XRay.
- Two handles are compared with ==. A handle can be the key of a TMap or a TSet. A new FLinesPlusHandle refers to no line.
Options
| Setting | Type | Values |
|---|---|---|
| Shape | ELinesPlusShape | Ribbon, FlatRibbon, Tube |
| Width Unit | ELinesPlusWidthUnit | World, Pixels |
| Corner | ELinesPlusCorner | Round, Sharp, Flat |
| Blend | ELinesPlusBlend | Opaque, Translucent, Additive |
| Pattern | ELinesPlusPattern | Solid, Dashed, Dotted, Chevrons |
| Start Cap, End Cap | ELinesPlusCap | Flat, Square, Round, Arrow |
| Draw Easing | ELinesPlusEasing | Linear, EaseIn, EaseOut, EaseInOut |
Draw and change a line
#include "LinesPlusLibrary.h"
FLinesPlusStyle Style;
Style.Color = FLinearColor::Red;
Style.Width = 6.0f;
Style.EndCap = ELinesPlusCap::Arrow;
FLinesPlusHandle Line = ULinesPlusLibrary::DrawLine(this, Start, End, Style);
ULinesPlusLibrary::SetLineColor(this, Line, FLinearColor::Green);
ULinesPlusLibrary::RemoveLine(this, Line);
A line component in your own actor
Declare the component in the header of the actor:
#include "LinesPlusComponent.h"
UPROPERTY(VisibleAnywhere)
TObjectPtr<ULinesPlusComponent> Cable;
Create it in the constructor:
Cable = CreateDefaultSubobject<ULinesPlusComponent>(TEXT("Cable"));
Cable->SetupAttachment(RootComponent);
Then set its look and its points, for example in BeginPlay. The points are relative to the component. After you change a member of the component directly, call Rebuild:
FLinesPlusStyle Style;
Style.Shape = ELinesPlusShape::Tube;
Style.Blend = ELinesPlusBlend::Opaque;
Style.bLit = true;
Style.bCastShadow = true;
Style.Width = 8.0f;
Cable->SetStyle(Style);
Cable->SetPoints({ FVector(0.0, 0.0, 0.0), FVector(100.0, 0.0, -40.0), FVector(200.0, 0.0, 0.0) });
Cable->bSmooth = true;
Cable->Rebuild();
A projectile path that lands on a target
#include "Kismet/GameplayStatics.h"
FVector Velocity;
UGameplayStatics::SuggestProjectileVelocity_CustomArc(this, Velocity, Start, Target);
FHitResult Hit;
Path = ULinesPlusLibrary::DrawTrajectory(this, Start, Velocity, Style, Hit);
Each time the start or the target changes, update the same line. The function returns true when the path hits something:
FVector Velocity;
UGameplayStatics::SuggestProjectileVelocity_CustomArc(this, Velocity, Start, Target);
FHitResult Hit;
if (ULinesPlusLibrary::UpdateTrajectory(this, Path, Start, Velocity, Hit))
{
Marker->SetWorldLocation(Hit.ImpactPoint);
}
Highlight the line under the cursor
The actor keeps the selected line and its look in two members, Selected and SelectedStyle. Call this code in each frame:
FLinesPlusHandle Found;
FVector Point;
const bool bFound = ULinesPlusLibrary::FindLineUnderCursor(this, Player, Found, Point);
if (bFound && Found == Selected) return;
ULinesPlusLibrary::SetLineStyle(this, Selected, SelectedStyle);
Selected = bFound ? Found : FLinesPlusHandle();
if (!bFound) return;
SelectedStyle = ULinesPlusLibrary::GetLineStyle(this, Found);
FLinesPlusStyle Highlighted = SelectedStyle;
Highlighted.Color = FLinearColor::White;
Highlighted.Width *= 2.0f;
ULinesPlusLibrary::SetLineStyle(this, Found, Highlighted);
Change a style asset from code
StyleAsset->Style.Color = FLinearColor::Yellow;
StyleAsset->UpdateLines();
The demo of the plugin is one more reference. See Demo.
Suggest an improvement
Help us improve this documentation page.