The Playground Spline

A diverse tool for creating and editing splines

Alongside the Particle Playground installation there’s a separate framework called Playground Spline included for creating and editing splines.

The Playground Spline can be used by any type of GameObject or component, to read positions in world space created by nodes and bezier curves. A Playground Spline’s nodes can be created and controlled using Vector3 values or by live Transforms within the scene.

See the Playground Spline video guide for further details.

A Quick Overview

Multithreading friendly

Read positions from a separate thread, regardless of using Transforms or Vector3 nodes.

Looping

Toggle loop to connect the start and end node seamlessly.

Overall time offset

Offset the entire spline’s time to easily move plenty of connected objects.

Works as a Transform

Position, rotate and scale the entire spline by its Transform.

Reversing

Toggle reverse to reverse the spline time.

Transform or Vector3 nodes

Setup your nodes with Transforms or Vector3 values. Using Transforms will let you easily reposition nodes during runtime.

Good performance

Reading values from the spline is extremely fast and adapted for thousands of calls each frame.

Scene View controls

Edit the spline directly in Scene View with a quick control window for fast navigation.

Node control through Inspector

Edit and rearrange the spline directly from the Inspector with an easy-to-use node list.

To create a Playground Spline you select a GameObject in Hierarchy and press Playground Spline found in the Playground Components section in the Playground Wizard (Window > Particle Playground).

Playground Spline

Loop
Determines if the spline’s start- and end nodes should be jointed. This is only available when having a minimum of three nodes.

Reverse
Reverse the normalized time over the spline. This will affect the values read from the spline (where for example a normalized time of 0.2 would become 0.8). Reversing the actual nodes can be done in the Nodes tab.

Time Offset
Determines an offset for the time on the spline. This will affect values read from the spline (where for example a normalized time of 0.2 with Time Offset 0.5 would output 0.7).

Position Offset
Offsets all nodes from the Transform origin.

Selection
The selected node in Scene View. Here you can see a node’s structure in the spline, iterate through them and set their local position. The Bezier Mode determines if left- and right bezier node should align mirror or be positioned unrelated to each other.

Add Node
Inserts a node into the spline based on your selection. You can also use Ctrl + Click in Scene View to add new node points.

Remove Selected Node
Removes the selected node from the spline. This is only available when having more than two nodes.

Nodes

Nodes
This is the list of nodes in the spline. By selecting one in the list you will also see its related bezier nodes. Both a node and a bezier node can be set towards a Vector3 value or a Transform’s position in the Scene. Use the up- and down arrow to sort the nodes. The + button will insert a new node, the – button will remove a node.

Create
Creates a new node at the end of the node list.

Convert All To Transforms
Converts all the spline’s nodes into a Transform structure in Hierarchy.

Convert All To Vector3
Converts all the spline’s nodes into Vector3 values from a Transform structure.

Reverse All Nodes
Reverses the array of nodes.

Used By

Contains a jump-list of all Particle Playground systems using this spline (as a Source or Target). You can remove the reference to a Particle Playground system by pressing the “-” button (this will not remove your particle system but only the reference to the spline).

Advanced

Velocity On New Node
Determines in which position a new node should be created. Nodes are created with a velocity based on the current selected node to make it faster to create shapes in the direction the spline’s nodes are currently in.

Move Transforms As Beziers
Determines if Transform nodes should act as bezier nodes and take the Bezier Mode into account when moving the Transform.

Export With Node Structure
Determines if a node hierarchy should be created when converting the nodes to Transforms (Nodes > Convert All To Transform).

Draw Bezier Gizmo
Determines if the bezier curve Gizmo should be drawn in Scene View.

Bezier Width
The width of the bezier Gizmo.

The Playground Spline framework is written in C# and ready for script control. Full source code available.

Get a world space position from a Playground Spline

GetPoint() will return a position based on the passed in time parameter. Time is a normalized float value from 0 to 1. Example:

using UnityEngine;
using PlaygroundSplines;

public class GetPositionFromSpline : MonoBehaviour {

    public PlaygroundSpline spline;
    public float time = .5f;

    void Start () {
        Vector3 position = spline.GetPoint (time);
    }
}

Get the velocity at position from a Playground Spline

GetVelocity() will return a velocity based on the passed in time parameter. Time is a normalized float value from 0 to 1. Example:

using UnityEngine;
using PlaygroundSplines;

public class GetVelocityFromSpline : MonoBehaviour {
    
    public PlaygroundSpline spline;
    public float time = .5f;
    
    void Start () {
        Vector3 velocity = spline.GetVelocity (time);
    }
}

Insert node into a Playground Spline

AddNode() will add a node point at the very last node index. AddNode(int) will insert a node point at specified index. Example:

using UnityEngine;
using PlaygroundSplines;

public class AddNodeIntoSpecificIndex : MonoBehaviour {

    public PlaygroundSpline spline;
    public int index = 10;

    void Start () {
        spline.AddNode(index);
    }
}

Remove node from a Playground Spline

RemoveFirst() will remove the very first node in the node index.
RemoveLast() will remove the very last node in the node index.
RemoveNode(int) will remove a node point at specified index. Example:

using UnityEngine;
using PlaygroundSplines;

public class RemoveNodeAtIndex : MonoBehaviour {

    public PlaygroundSpline spline;
    public int index = 10;

    void Start () {
        spline.RemoveNode(index);
    }
}

Set node/bezier handle position of a Playground Spline

When using Transforms as node/bezier mode all you need to do is move your transform in the scene. Using Vector3 as mode SetControlPoint(int, Vector3) will set the passed in specified index to position. Example:

using UnityEngine;
using PlaygroundSplines;

public class SetNodePosition : MonoBehaviour {

    public PlaygroundSpline spline;
    public int index = 10;
    public Vector3 position = Vector3.up;

    void Start () {
        spline.SetControlPoint(indexposition);
    }
}

Offset time of a Playground Spline

You can offset the entire spline time if you for example want to move many objects with the same rate. Example:

using UnityEngine;
using PlaygroundSplines;

public class TimeOffsetPlaygroundSpline : MonoBehaviour {

    public PlaygroundSpline spline;
    public float offsetSpeed = 1f;

    void Update () {
        spline.timeOffset = offsetSpeed*Time.deltaTime;
    }
}