githubEdit

Working with Components

Add interactivity using built-in and custom components

Components are the building blocks of interactivity in Needle Engine. Add them to objects in Blender to create interactive behaviors, from simple camera controls to complex game mechanics.


Built-in Components

Needle Engine includes 100+ ready-to-use components for common interactive features.

Adding Components

In Blender:

  1. Select an object in your scene

  2. Open the Needle Components panel (usually in the Properties area)

  3. Click Add Component

  4. Search for and select the component you need

  5. Adjust component settings in the panel

Component settings appear immediately after adding. Each component has different properties you can configure directly in Blender.


Example: Camera Controls

Add OrbitControls to your camera for instant mouse/touch controls on all devices:

OrbitControls settings:

  • target - What the camera orbits around

  • autoRotate - Automatic rotation

  • enableDamping - Smooth camera movement

  • minDistance / maxDistance - Zoom limits

  • enablePan - Allow panning with right-click


Camera Controls:

  • OrbitControls - Orbit around a target with mouse/touch

Animation:

Interaction:

  • DragControls - Make objects draggable in 3D space

  • ObjectRaycaster - Detect clicks and hover on objects

UI & UX:

  • Button - Interactive buttons

  • Canvas - UI container

Media:

  • VideoPlayer - Play video files and streams

Physics:

  • Rigidbody - Add physics simulation

  • BoxCollider / SphereCollider / MeshCollider - Collision shapes

Audio:

  • AudioSource - 3D spatial audio

  • AudioListener - Hear 3D audio (usually on camera)

Effects:

  • ParticleSystem - Visual effects

  • Light - Dynamic lighting

Optimization:

  • ViewBox - Ensure content stays framed

XR (Virtual & Augmented Reality):

Actions & Events:

  • EverywhereActions - Trigger actions on various events (click, hover, collision, etc.)

See all 100+ components →arrow-up-right


Removing Components

Click the X button in the lower right of any component panel.


Custom Components

Want behavior that doesn't exist yet? Write your own TypeScript components that automatically appear in Blender.

Creating Custom Components

1. Open Your Project Code

Click Code Editor in the Needle Project panel to open VS Code with your web project.

2. Create a Component File

In your project, navigate to src/scripts/ and create a new .ts file (e.g., RotateObject.ts).

3. Write Your Component

4. Save and Use

  • Save the file

  • The component automatically compiles

  • It appears in Blender's component list

  • Add it to objects just like built-in components

  • Your @serializable() properties appear as editable fields in Blender


Component Lifecycle

Components have lifecycle methods you can override:

Learn more about lifecycle hooks →arrow-up-right


Accessing Other Components

Find components on the same object:

Find components in children:

Find components in parents:

Find components anywhere in scene:

Learn more about finding objects and components →arrow-up-right


Serializable Properties

Use @serializable() to expose properties in Blender:

All these properties become editable in Blender's component panel!

:::tip Learn More


Component Communication

Using Events:

In Blender, assign the Door's open() method to the Button's onClick event.

Direct References:

Assign the animator reference in Blender by dragging the component.


Best Practices

Component Design:

  • Keep components small and focused (single responsibility)

  • Use @serializable() for values artists should control

  • Provide sensible defaults

  • Add comments to explain parameters

Performance:

  • Avoid heavy calculations in update() - use onEnable() when possible

  • Cache component references in awake() or start()

  • Use object pooling for frequently created/destroyed objects

Organization:

  • Group related components in the same file or folder

  • Use clear, descriptive class names

  • Follow TypeScript naming conventions


Requirements

:::warning Component Compiler Required Make sure @needle-tools/needle-component-compiler 2.x is in your package.json devDependencies for component hot-reloading to work. :::

This is included by default in new projects. If components aren't appearing in Blender, check your package.json.


Next Steps


Need Help?

Last updated