---
title: "setConstantValue(_:type:index:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtlfunctionconstantvalues/setconstantvalue(_:type:index:)"
---

# setConstantValue(_:type:index:)

Sets a value for a function constant at a specific index.

## Declaration

```swift
func setConstantValue(_ value: UnsafeRawPointer, type: MTLDataType, index: Int)
```

## Parameters

- `value`: A pointer to the constant value.
- `type`: The data type of the function constant.
- `index`: The index of the function constant.

## Discussion

Discussion Declare a single function constant in Metal Shading Language (MSL). constant bool a [[ function_constant(0) ]]; Set its value by assigning with a specific index.

## See Also

### Related Documentation

- [Metal Shading Language Guide](apple-archive/documentation/Metal/Reference/MetalShadingLanguageGuide/Introduction.md)
- [Metal Programming Guide](apple-archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Introduction.md)

### Setting constant values

- [setConstantValue(_:type:withName:)](metal/mtlfunctionconstantvalues/setconstantvalue(_:type:withname:).md)
- [setConstantValues(_:type:range:)](metal/mtlfunctionconstantvalues/setconstantvalues(_:type:range:).md)
