One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

OpacityComponent

struct · iOS 18.0+ · SDK 27.1

struct OpacityComponent

A component that controls the opacity of an entity and its descendants. An opacity component multiplies its ``OpacityComponent/opacity`` property with all visual components the entity and its descendants own. Visual components include ``ModelComponent`` and ``ParticleEmitterComponent``. If a descendant also has its own opacity component, the system combines the two opacities by multiplying their values. The system repeats this pattern for the entity's entire family tree. For example, the following code sets a component's opacity value to `0.5` for its entity: ```swift // Load a USDZ model from a file, or create a model component. let robot = try await Entity(named: "vintage_robot") // Create an opacity component. let opacityComponent = OpacityComponent(opacity: 0.5) // Apply the opacity component to the robot entity. robot.components.set(opacityComponent) ``` The following images show robot models with opacity values of `1.0` and `0.5`. | `opacity: 1` | `opacity: 0.5` | |:-:|:-:| | ![An image of an opaque vintage-style toy robot in a living room scene. The robot is facing about 45 degrees to the left and down from the viewer's perspective.](opacitycomponent-full) | ![An image of a translucent vintage-style toy robot in a living room scene. The robot is facing about 45 degrees to the left and down from the viewer's perspective.](opacitycomponent-half) |

Members (3)

init · iOS 18.0+

init

TypeScript
static init(opacity?: number): OpacityComponent
Swift declaration
init(opacity: Float = 1.0)

Creates a new opacity component. - Parameters: - opacity: A floating-point value in the range `[0.0, 1.0]`, where `0.0` is completely transparent and `1.0` is completely opaque.

get · iOS 18.0+

opacity

TypeScript
get opacity(): number
Swift declaration
var opacity: Float

The floating-point value the renderer applies to an entity and its descendants. The opacity is a float within the inclusive range `[0.0, 1.0]`, where `0.0` is completely transparent and `1.0` is completely opaque.

set · iOS 18.0+

opacity

TypeScript
set opacity(value: number)
Swift declaration
var opacity: Float

The floating-point value the renderer applies to an entity and its descendants. The opacity is a float within the inclusive range `[0.0, 1.0]`, where `0.0` is completely transparent and `1.0` is completely opaque.

Skipped declarations

No declarations were skipped in this snapshot.

All RealityFoundation types →