Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Components

Nightshade provides 59 built-in components across several categories. Core components (45) are listed below. UI components (10) are covered in Retained UI and Sprite2D components (4) in Sprites.

Transform Components

ComponentDescription
LocalTransformPosition, rotation, scale relative to parent
GlobalTransformComputed world-space transformation matrix
LocalTransformDirtyMarker for transforms needing propagation
ParentParent entity reference for hierarchy
IgnoreParentScaleExclude parent's scale from transform hierarchy
RotationAdditional rotation component
#![allow(unused)]
fn main() {
pub struct LocalTransform {
    pub translation: Vec3,
    pub rotation: Quat,
    pub scale: Vec3,
}

pub struct GlobalTransform(pub Mat4);

pub struct Parent(pub Option<Entity>);
}

Rendering Components

ComponentDescription
RenderMeshReferences mesh by name
MaterialRefReferences material by name
Sprite2D billboard rendering
RenderLayerDepth/layer for ordering
CastsShadowMarks mesh for shadow maps
VisibilityVisibility toggle
BoundingVolumeBounding volume for culling and picking
InstancedMeshGPU-instanced mesh data
#![allow(unused)]
fn main() {
pub struct RenderMesh {
    pub name: String,
    pub id: Option<MeshId>,
}

pub struct MaterialRef {
    pub name: String,
    pub id: Option<MaterialId>,
}
}

MaterialRef::new(name) takes impl Into<String>, so you can pass &str directly:

#![allow(unused)]
fn main() {
MaterialRef::new("Default")
}

Camera Components

ComponentDescription
CameraProjection mode and smoothing
PanOrbitCameraOrbiting camera controller

There is a single CAMERA component flag. The projection type is determined by the Projection enum inside the Camera struct:

#![allow(unused)]
fn main() {
pub struct Camera {
    pub projection: Projection,
    pub smoothing: Option<Smoothing>,
}

pub enum Projection {
    Perspective(PerspectiveCamera),
    Orthographic(OrthographicCamera),
}

pub struct PerspectiveCamera {
    pub aspect_ratio: Option<f32>,
    pub y_fov_rad: f32,
    pub z_far: Option<f32>,
    pub z_near: f32,
}

pub struct OrthographicCamera {
    pub x_mag: f32,
    pub y_mag: f32,
    pub z_far: f32,
    pub z_near: f32,
}
}

Lighting

ComponentDescription
LightDirectional, Point, or Spot light
#![allow(unused)]
fn main() {
pub struct Light {
    pub light_type: LightType,
    pub color: Vec3,
    pub intensity: f32,
    pub range: f32,
    pub cast_shadows: bool,
    pub shadow_bias: f32,
    pub inner_cone_angle: f32,
    pub outer_cone_angle: f32,
}

pub enum LightType {
    Directional,
    Point,
    Spot,
}
}

Physics Components

ComponentDescription
RigidBodyComponentDynamic/Fixed/Kinematic body
ColliderComponentCollision shape
CharacterControllerComponentKinematic player controller
PhysicsInterpolationSmooth physics rendering
CollisionListenerReceives collision events
#![allow(unused)]
fn main() {
pub struct RigidBodyComponent {
    pub handle: Option<RigidBodyHandle>,
    pub body_type: RigidBodyType,
    pub translation: [f32; 3],
    pub rotation: [f32; 4],
    pub linvel: [f32; 3],
    pub angvel: [f32; 3],
    pub mass: f32,
    pub locked_axes: LockedAxes,
}

pub enum RigidBodyType {
    Dynamic,
    Fixed,
    KinematicPositionBased,
    KinematicVelocityBased,
}
}

Constructor methods:

  • RigidBodyComponent::new_dynamic()
  • RigidBodyComponent::new_static() (creates a Fixed body type)
  • RigidBodyComponent::new_kinematic() (creates KinematicPositionBased)

The component flag for rigid bodies is RIGID_BODY (not RIGID_BODY_COMPONENT).

Animation Components

ComponentDescription
AnimationPlayerAnimation playback control
SkinSkeleton definition
JointBone in skeleton
MorphWeightsBlend shape weights
#![allow(unused)]
fn main() {
pub struct AnimationPlayer {
    pub clips: Vec<AnimationClip>,
    pub current_clip: Option<usize>,
    pub blend_from_clip: Option<usize>,
    pub blend_factor: f32,
    pub playing: bool,
    pub speed: f32,
    pub time: f32,
    pub looping: bool,
}
}

Audio Components

ComponentDescription
AudioSourceSound playback
AudioListener3D audio receiver

Text Components

ComponentDescription
Text3D world text and screen-space UI text
TextCharacterColorsPer-character text colors
TextCharacterBackgroundColorsPer-character text background colors

Geometry Components

ComponentDescription
LinesDebug line rendering
#![allow(unused)]
fn main() {
pub struct Lines {
    pub lines: Vec<Line>,
}

pub struct Line {
    pub start: Vec3,
    pub end: Vec3,
    pub color: Vec4,
}
}

Advanced Components

ComponentDescription
ParticleEmitterGPU particle system
GrassRegionProcedural grass field
GrassInteractorGrass bending interaction
NavMeshAgentAI pathfinding agent
WaterWater surface/volume
DecalProjected texture
LatticeLattice deformation controller
LatticeInfluencedEntity deformed by a lattice
TweenTween animation component
PrefabSourceSource prefab reference
PrefabInstanceInstance of a spawned prefab
ScriptScripting component (requires scripting feature)
HoveredInput hover state
NameString identifier