Scripting Support (C#)
advanced scriptingTrails FX · Scripting Support (C#)
TrailEffect component (namespace TrailsFX). Access via GetComponent<TrailEffect>().
Getting Started
Add the namespace and get a reference to the component:
using TrailsFX;
TrailEffect trail = GetComponent<TrailEffect>();
Core Properties
bool active
IncludedTarget[] includeExecution
bool executeInEditModeEnable trail generation in the Unity Editor (edit mode).
int ignoreFramesNumber of initial frames to skip before starting trail generation.
Array of additional targets to include in trail generation.
bool combineMeshesWithChildrenCombine meshes with children renderers into a single trail.
Enable or disable trail generation.
TrailStyle effectVisual style of the trail: Color, TextureStamp, Clone, Outline, SpaceDistortion, Dash, or Custom.
float durationDuration of the trail effect in seconds. Default: 0.5.
bool continuousGenerate trails continuously (useful for persistent motion trails).
Transform targetTarget renderer to create trails from. If null, uses the object's own renderer.
TrailEffectProfile profileTrail effect profile asset for preset configurations.
bool profileSyncAutomatically sync settings when the profile changes.
Trail Triggering Conditions
bool checkWorldPosition
PositionChangeRelative worldPositionRelativeOptionPosition change reference: World or OtherTransform.
Transform worldPositionRelativeTransformReference transform for relative position change detection.
Trigger trail snapshots when the object moves in world space.
float minDistanceMinimum world-space distance to trigger a new snapshot. Default: 0.1.
bool checkScreenPositionTrigger snapshots when the object moves on screen. Default: true.
int minPixelDistanceMinimum pixel distance to trigger a new snapshot. Default: 10.
bool checkTimeTrigger snapshots based on a time interval.
float timeIntervalTime in seconds between snapshots when checkTime is enabled.
bool checkCollisionsTrigger trail snapshots on collision detection.
LayerMask collisionLayerMaskLayer mask for collision-based trail triggering.
Mask & Stencil
Texture2D maskMask texture for limiting trail generation to specific areas.
bool clearStencilClear the stencil buffer before rendering the trail.
bool hierarchyOccluderEnable hierarchy-based occlusion for trail rendering.
Transform hierarchyOccluderRootRoot transform for hierarchy occluder detection.
LayerMask hierarchyOccluderLayerMaskLayer mask for hierarchy occluder detection.
bool hierarchyIncludeInactiveInclude inactive GameObjects in hierarchy occluder detection. Default: true.
Color & Appearance
Color color
bool colorCycleLoopLoop the color cycle animation. Default: true.
float pingPongSpeedSpeed of the ping-pong color animation. Default: 1.
bool colorRampEnable color ramp based on world-space position.
Texture2D colorRampTextureTexture used for color ramp sampling.
Transform colorRampStartStart transform for color ramp world-space mapping.
Transform colorRampEndEnd transform for color ramp world-space mapping.
Base trail color.
Gradient colorOverTimeColor progression over the trail lifetime.
ColorSequence colorSequenceColor mode: Fixed, Cycle, PingPong, Random, or FixedRandom.
Gradient colorStartPalettePalette gradient used for color sequences.
float colorCycleDurationDuration of one full color cycle in seconds.
bool fadeOutFade trail alpha over time. Default: true.
Texture2D textureTexture used for the trail (for TextureStamp style).
float textureCutOffAlpha cutoff threshold for texture (0–1). Default: 0.25.
Color trailTintTint color used for the SpaceDistortion effect.
Scale & Position
Vector3 scale
Vector3 scaleStartRandomMinMinimum random scale applied to new trail snapshots. Default: Vector3.one.
Vector3 scaleStartRandomMaxMaximum random scale applied to new trail snapshots. Default: Vector3.one.
bool ignoreTransformScaleIgnore the object's transform scale when generating trail snapshots.
Base scale of the trail snapshots.
AnimationCurve scaleOverTimeScale progression over the trail lifetime.
bool scaleUniformApply uniform scaling to all axes.
Vector3 localPositionRandomMinMinimum random local position offset per snapshot.
Vector3 localPositionRandomMaxMaximum random local position offset per snapshot.
Transform lookTargetTarget transform that trail snapshots orient toward.
bool lookToCameraOrient trail snapshots toward the camera. Default: true.
Surface & Ground Alignment
bool groundSnap trail to the ground surface.
bool orientToSurfaceOrient trail snapshots to match the surface normal. Default: true.
float surfaceOffsetOffset from the surface to prevent z-fighting. Default: 0.05.
Smoothing & Performance
bool smoothCreate smooth trails with interpolated steps.
int maxStepsPerFrameMaximum trail snapshots per frame. Default: 12.
int stepsBufferSizeTotal trail buffer capacity. Default: 1023.
int maxBatchesMaximum render batches. Default: 50.
int meshPoolSizePool size for dynamically allocated meshes. Default: 256.
Rendering
TrailRenderOrder renderOrder
CullMode cullModeFace culling mode for trail rendering. Default: Back.
int subMeshMaskBitmask for sub-mesh selection (-1 = all sub-meshes). Default: -1.
Camera camCamera used for trail rendering. If null, uses the main camera.
Render order: BeforeObject, DrawBehind (default), or AlwaysOnTop.
bool ignoreVisibilityGenerate trails even when the renderer is not visible.
Material customMaterialCustom material used when effect is set to TrailStyle.Custom.
bool cameraDistanceFadeFade trail based on camera distance.
float cameraDistanceFadeNearNear fade distance.
float cameraDistanceFadeFarFar fade distance. Default: 1000.
Laser / Dash Effect
float laserBandWidthWidth of the laser band. Default: 0.1.
float laserIntensityLaser intensity multiplier. Default: 20.
float laserFlashLaser flash duration. Default: 0.2.
Outline Effect Settings
OutlineMethod outlineMethodOutline detection: Normals or Rim.
float normalThresholdNormal threshold for outline detection (0–1). Default: 0.3.
float rimPowerRim lighting power for rim-based outlines. Default: 2.
Animation State Filtering
Animator animatorAnimator component for animation-state-based trail filtering.
string animationStatesComma-separated animation state names. Supports time ranges: "Attack(0.1-1.5)".
bool useLastAnimationStateUse only the last animation frame for the trail.
Other Settings
Transform parentParent transform for trail snapshots. If set, trail snapshots are parented to this transform.
bool preserveMultiMaterialsPreserve multiple materials on cloned trail meshes.
bool interpolateEnable interpolation between trail snapshots for smoother trails.
Methods
void Clear()
void CheckEditorSettings()Validates and updates editor-specific settings. Call after changing properties that affect editor preview.
void RefreshHierarchyOccluders()Refreshes the hierarchy occluder cache. Call after modifying hierarchy occluder settings at runtime.
Clears the current trail and restarts the cycle.
void Restart()Restarts the trail cycle but keeps existing trail snapshots visible.
void Refresh()Refreshes internal caches (children renderers, hierarchy occluders). Call after modifying included targets at runtime.
void UpdateMaterialProperties()Updates all material properties. Call after changing visual properties via script.
void SetProfile(TrailEffectProfile profile)Loads and applies a different trail profile.
Vector3 GetTrailPosition(int index)Returns the world-space position of a trail snapshot at the given index.
- index
- Index of the trail snapshot (0 to stepsBufferSize-1).
Enums Reference
World, OtherTransform
Color, TextureStamp, Clone, Outline, SpaceDistortion, Dash, Custom
Fixed, Cycle, PingPong, Random, FixedRandom
BeforeObject, DrawBehind, AlwaysOnTop
Normals, Rim
Code Examples
using UnityEngine;
using TrailsFX;
public class TrailDemo : MonoBehaviour {
TrailEffect trail;
void Start() {
trail = GetComponent<TrailEffect>();
// Configure a color trail
trail.effect = TrailStyle.Color;
trail.color = Color.cyan;
trail.duration = 0.8f;
trail.fadeOut = true;
// Trigger on world-space movement
trail.checkWorldPosition = true;
trail.minDistance = 0.05f;
// Enable continuous generation
trail.continuous = true;
// Start the trail
trail.active = true;
}
void ResetTrail() {
// Clear all visible trail snapshots
trail.Clear();
}
}
// Clone-based trail with animation filtering
public class CloneTrailDemo : MonoBehaviour {
void Start() {
var trail = GetComponent<TrailEffect>();
trail.effect = TrailStyle.Clone;
trail.duration = 1.0f;
// Only generate trail during "Attack" animation
trail.animator = GetComponent<Animator>();
trail.animationStates = "Attack(0.1-0.9)";
trail.active = true;
}
}
Suggest an improvement
Help us improve this documentation page.