<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/CustomMaterial/GeometryModifier/init(named:in:constantValues:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation14CustomMaterialV16GeometryModifierV5named2in14constantValuesAESS_So10MTLLibrary_pSo019MTLFunctionConstantJ0Ctcfc"
  },
  "title" : "init(named:in:constantValues:)"
}
-->

# init(named:in:constantValues:)

Creates a geometry modifier with the specified function constant values.

```
init(named name: String, in library: any MTLLibrary, constantValues: MTLFunctionConstantValues)
```

## Discussion

Function constants allow you to better share code or toggle features in your shaders
without runtime performance costs by resolving their values at compile time.

To use function constants, first define them within your metal code:

```cpp
constant bool kEnableVertexAnimation [[function_constant(0)]];

[[stitchable]]
void geometryModifier(realitykit::geometry_parameters params) {
    if (kEnableVertexAnimation) {
        float currentTime = params.uniforms().time() * 0.5;
        params.geometry().set_model_position_offset(sin(currentTime) * 0.1 * params.geometry().normal());
    }
}
```

Then initialize a geometry modifier with a `Metal/MTLFunctionConstantValues` object that defines values for your constants.

```swift
let constants = MTLFunctionConstantValues()
var yes = true
funcConstants.setConstantValue(&yes, type: .bool, index: 0)

let geom = CustomMaterial.GeometryModifier.init(named: "geometryModifier", in: library, constantValues: constants)
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)