• Iterates over all components on an Object3D and optionally its children. The callback can return a value to stop iteration early.

    Parameters

    • instance: Object3D

      The Object3D to iterate components on

    • cb: ForEachComponentCallback

      Callback function called for each component. Return a value to stop iteration.

    • recursive: boolean = true

      If true (default), also iterates components on all children

    Returns any

    The first non-undefined value returned by the callback, or undefined

    const rb = foreachComponent(myObject, comp => {
    if (comp instanceof Rigidbody) return comp;
    });