Class Destructable

Component that enables meshes to be fractured into debris pieces when damaged beyond their health threshold.

Works in conjunction with Renderable for mesh visualization and Rigidbody/Collider for physics-based debris simulation.

The destruction system requires a valid DestructionResource to provide the FracturePiece data at runtime.

Hierarchy (view full)

Constructors

Accessors

  • get active(): boolean
  • Activates or deactivates the component.

    Returns boolean

    The returned active state also accounts for the active state of the parent SceneObject.

  • set active(value): void
  • Parameters

    • value: boolean

    Returns void

  • get baseDamageToBreak(): number
  • Sets the base damage required to break an average-sized piece.

    Returns number

  • set baseDamageToBreak(value): void
  • Parameters

    • value: number

    Returns void

  • get collisionDamageMultiplier(): number
  • Sets the collision impulse to damage multiplier. When the DamageOnCollision flag is set, collision impulse * this value = damage applied.

    Returns number

  • set collisionDamageMultiplier(value): void
  • Parameters

    • value: number

    Returns void

  • get currentHealth(): number
  • Sets the current health of the destructable.

    Returns number

  • set currentHealth(value): void
  • Parameters

    • value: number

    Returns void

  • get damageRadiusMultiplier(): number
  • Sets the multiplier applied when on the damage radius when receiving damage.

    Returns number

  • set damageRadiusMultiplier(value): void
  • Parameters

    • value: number

    Returns void

  • get damageThreshold(): number
  • Sets the threshold below which damage is ignored.

    Returns number

    This is useful for making objects immune to small impacts, or avoid too much fracture when DamageOnCollision is enabled.

  • set damageThreshold(value): void
  • Parameters

    • value: number

    Returns void

  • get debrisImpulseMultiplier(): number
  • Sets the multiplier applied to the impulse strength when damage is applied.

    Returns number

  • set debrisImpulseMultiplier(value): void
  • Parameters

    • value: number

    Returns void

  • get debrisLifetime(): number
  • Sets the lifetime of debris pieces in seconds. After this time, debris will be automatically cleaned up. Set to 0 for infinite lifetime.

    Returns number

  • set debrisLifetime(value): void
  • Parameters

    • value: number

    Returns void

  • get destructionResource(): DestructionResource
  • Sets the destruction resource containing pre-computed fracture data.

    Returns DestructionResource

    If no resource is assigned, the component will attempt to generate fracture data at runtime using the mesh from the CRenderable component.

  • set destructionResource(value): void
  • Sets the destruction resource containing pre-computed fracture data.

    Parameters

    Returns void

    If no resource is assigned, the component will attempt to generate fracture data at runtime using the mesh from the CRenderable component.

  • get editorMetaData(): Settings
  • Get the editor meta data.

    Returns Settings

    The API is only valid in the editor.

  • get healthAsPercentage(): number
  • Returns the health as a percentage [0...1].

    Returns number

  • get isActiveSelf(): boolean
  • Determines whether the component itself is active, without accounting for the active state of the parent scene object.

    Returns boolean

  • get isDestroyed(): boolean
  • Returns true if the destructable has been destroyed.

    Returns boolean

  • get isIntact(): boolean
  • Returns true if the destructable is intact (not destroyed).

    Returns boolean

  • get isRunning(): boolean
  • Determines if the component is currently active, enabled and running.

    Returns boolean

  • get lodScreenCoverage(): number
  • Sets the LOD screen coverage threshold (in percent) for debris.

    For each additional LOD level, the screen coverage is halved (e.g. 0.05, 0.025, 0.0125, ...).

    Returns number

    This is only relevant if the destruction resource contain LOD data. Debris chunks are typically small and numerous, thus the LOD screen coverage should be fairly small (e.g. 0.05 = 5% of screen height) to avoid visible LOD popping on a slightly fractured object.

  • set lodScreenCoverage(value): void
  • Parameters

    • value: number

    Returns void

  • get maximumCollisionDamage(): number
  • Sets the maximum collision damage that can be applied.

    It is recommended to set this value to a bit higher than the base damage to break value.

    Returns number

    This is helpful to prevent to intense destruction when rigid bodies might not be able to resolve forces properly.

  • set maximumCollisionDamage(value): void
  • Parameters

    • value: number

    Returns void

  • get maximumHealth(): number
  • Sets the maximum health of the destructable.

    Returns number

  • set maximumHealth(value): void
  • Parameters

    • value: number

    Returns void

  • get priority(): number
  • The signed execution priority of the component.

    Determines order of execution of this component in relation to other components, higher priorities will execute earlier. The priority value determines the order of initialize, enable and update calls. Valid priorities are in the range [-100...100], other priorities are reserved for internal use.

    The priority should not be modified after onCreate has been called.

    The default priority for user implement components is -10. BuiltinComponent have a default priority of 0. However, instances that have dependencies or are a dependency to another component might have non zero default priorities. For example, the Camera component has a default priority of 50 as other components may depend on the camera being initialized early. The Rigidbody component has a default priority of 22 and Joint components have a priority of 20 as the joint depends on fully initialized rigid bodies.

    Returns number

    If two components have the same priority, the order of execution is undefined, but deterministic as the system uses identifiers such as the internal type ID and UUID to guaranteed stable ordering.

  • set priority(value): void
  • Parameters

    • value: number

    Returns void

  • get uuid(): UUID
  • Returns a universally unique identifier that persists scene save/load.

    Returns UUID

Methods

  • Applies damage to the destructable.

    Parameters

    • damage: number

      The amount of damage to apply.

    • Optionalposition: Immutable<Vector3>

      The optional world position where damage was applied. If not specified, the destructable's world position is used.

    • Optionaldirection: Immutable<Vector3>

      The optional direction from which damage was applied.

    • Optionalradius: number

      The optional radius of the damage area. Default is 0.25f, equals 25cm.

    • Optionalimpulse: number

      The optional impulse force to apply to debris. Default is 1.0f.

    • OptionalsourceComponent: Component

      Optional component that caused the damage.

    Returns boolean

    True if the damage was applied (object was not already destroyed).

  • Applies damage using a DamageData struct.

    Parameters

    Returns boolean

    True if the damage was applied (object was not already destroyed).

  • Virtual

    Calculates bounds of the visible content for this component.

    Returns {
        box: AABox;
        sphere: Sphere;
    }

    An object with the bounding box and bounding sphere or null, if the component has no bounds.

  • Destroys the component, removing it from its scene object and stopping component updates.

    Parameters

    • Optionalimmediate: boolean

      If true the component will be fully destroyed immediately. This means that objects that are still referencing this component might fail. Normally destruction is delayed until the end of the frame to give other objects a chance to stop using it.

    Returns void

  • Instantly destroys the destructable, ignoring remaining health.

    Parameters

    • Optionalposition: Immutable<Vector3>

      The world position to apply destruction impulse.

    • Optionalimpulse: number

      The impulse force to apply to debris.

    Returns void

  • Virtual

    Returns the bounds of the visible content for this component in local space, i.e. relative to the scene object's transform.

    Returns {
        box: AABox;
        sphere: Sphere;
    }

    An object with the bounding box and bounding sphere or null, if the component has no bounds.

  • Calls a parameterless method with the specified name, on the component.

    Parameters

    • name: string

      Name of the method to call.

    Returns boolean

    true if the method was invoked.

  • Virtual

    Called once when the component has been created.

    Returns void

    Called regardless of the state the component is in.

  • Virtual

    Called once just before the component is destroyed.

    Returns void

    Called regardless of the state the component is in.

  • Virtual

    Called every time a component is placed into the Stopped state.

    Returns void

    This method may be called during component destruction, if the component wasn't already in ScenePlayState.Stopped state during destruction. When called during destruction, it is called before onDestroy.

  • Virtual

    Called every time a component leaves the ScenePlayState.Stopped state.

    Returns void

    This method might be called during component creation, if the requirements for leaving the stopped state are met. One such case would be a component class that has the runInEditor attribute. When called during creation it is called after onInitialize.

  • Called at fixed time intervals (e.g. 60 times per frame). Only called if the component is in ScenePlayState.Playing state.

    Returns void

    RSX uses the fixed update to perform updates to sub-systems such as physics. Only implement this method if your logic depends on fixed updates (e.g. at 30hz) for stability.

  • Virtual

    Called once when the component first leaves the ScenePlayState.Stopped state.

    Returns void

    This method might be called during component creation, if the requirements for leaving the stopped state are met. One such case would be a component class that has the runInEditor attribute. When called during creation it is called after onCreate.

  • Virtual

    Called once per frame, after all other components received their onUpdate invocation. Only called if the component is in ScenePlayState.Playing state.

    Returns void

    This method should only be implemented if your component needs logic that implements on other component or SceneObject changes performend in onUpdate. An example could be a camera controller logic that updates in response to changes to the object that is being tracked.

  • Virtual

    Called when the script domain has been refreshed or when the component is initialized. During initialization it is called after onInitialize but before onEnable.

    Returns void

    This API will not be called in a deployment build.

  • Resets the destructable to its initial intact state.

    Returns void

    This will restore health and re-enable the original mesh.

  • Registers the coroutine for the specified component using the provided args as arguments.

    Type Parameters

    Parameters

    • coroutine: T

      The coroutine.

    • Rest...args: Parameters<T>

    Returns boolean

    true if the coroutine was registered.

    The coroutine will be called for the first time when the coroutine subsystem runs for update events. There is no guarantee with regards to the order of how coroutines are invoked. Coroutines are a great way for time-deferred or delayed system. To implement a coroutine simply add a generator method to your component and register it as coroutine:

    		public *myCoroutine(text:string)
    {
    const endTime:number = Time.realElapsed + 3;

    while(Time.realElapsed < endTime)
    {
    yield true;
    }

    Debug.log("This code will be invoked after 3 seconds with the text=" + text);
    }

    To register the function simply call

    		this.startCoroutine(this.myCoroutine, "Hello World!");
    

    The function will be invoked once the coroutine runs. The coroutine function can yield the program control flow by using the keyword yield. The coroutine will then stop execution at that point, and pick up the execution in the next update event, right after the yield keyword that caused the coroutine to pause.

    With helper functions such as waitForSeconds or waitForAsyncOp it is easy to create coroutines that pause for a set time interval.

  • Registers the coroutine for the specified component using the provided args as arguments.

    Type Parameters

    Parameters

    • coroutine: T

      The coroutine.

    • Rest...args: Parameters<T>

    Returns boolean

    true if the coroutine was registered.

    The coroutine will be called for the first time when the coroutine subsystem runs for fixedUpdate events. There is no guarantee with regards to the order of how coroutines are invoked. Coroutines are a great way for time-deferred or delayed system. To implement a coroutine simply add a generator method to your component and register it as coroutine:

    		public *myCoroutine(text:string)
    {
    const endTime:number = Time.realElapsed + 3;

    while(Time.realElapsed < endTime)
    {
    yield true;
    }

    Debug.log("This code will be invoked after 3 seconds!");
    }

    To register the function simply call

    		this.startCoroutine(this.myCoroutine, "Hello World!");
    

    The function will be invoked once the coroutine runs. The coroutine function can yield the program control flow by using the keyword yield. The coroutine will then stop execution at that point, and pick up the execution in the next fixedUpdate event, right after the yield keyword that caused the coroutine to pause.

    With helper functions such as waitForSeconds or waitForAsyncOp it is easy to create coroutines that pause for a set time interval.

  • Stops all coroutines for the specified component.

    Returns void

    This API is only available for components that are registered in a scene.

  • Stops the coroutine for the specified component.

    Parameters

    Returns boolean

    true if the coroutine was registered.

  • Locates a rsx object by its sceneRuntimeID and UUID.

    Parameters

    • sceneRuntimeID: number

      The runtime ID of the SceneInstance of the object.

    • uuid: Const<UUID>

      The UUID of the object to retrieve.

    Returns SceneNode

    The object or null if no object with given sceneRuntimeID and uuid has been registered

Events

onDamage: Event<[p0: Immutable<DamageData>], void>

Event triggered when damage is applied to the destructable.

Information about the damage applied.

onDestruct: Event<[p0: Immutable<DamageData>], void>

Event triggered when the destructable is destroyed (health reaches 0).

The position where destruction occurred.

The impulse applied during destruction.

onDebrisSpawned: Event<[p0: readonly SceneObject[]], void>

Event triggered when debris is spawned.

The scene objects created as debris.