Iterates over all components on an Object3D and optionally its children. The callback can return a value to stop iteration early.
The Object3D to iterate components on
Callback function called for each component. Return a value to stop iteration.
If true (default), also iterates components on all children
The first non-undefined value returned by the callback, or undefined
const rb = foreachComponent(myObject, comp => { if (comp instanceof Rigidbody) return comp;}); Copy
const rb = foreachComponent(myObject, comp => { if (comp instanceof Rigidbody) return comp;});
Iterates over all components on an Object3D and optionally its children. The callback can return a value to stop iteration early.