Behavior
Updated
Holds a user script and its run order.
- Type
comp-behavior- Script class
BehaviorComponent- Per entity
- One
- Version
- 1.0.0
Read about it in Behavior scripts: what it does, how to use it from a script, and examples.
Properties
Section titled “Properties”The props the runtime declares for this component, with their defaults and accepted ranges.
| Prop | Default | Range |
|---|---|---|
execution |
-, integer |
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
Live example
Edge detection with OpenCV.jsOpenCV.js, imported from a CDN, finds the edges in a picture drawn on a script canvas with Canny edge detection, and two planes show the picture and its edges side by side.
OpenCV.js is an 11 MB download (2.8 MB compressed): wait a few seconds for the edges to appear. Then click the scene and press Space to try other thresholds. Drag to orbit the camera, scroll to zoom.
From a script
Section titled “From a script”#pragma lifecycle(startup)
function startup() { const component = self.parent.getComponent(BehaviorComponent); if (component) log(component.props);}