ShaderGraphMaterial.getParameter(handle:) always return nil, is this expected behavior?

I've loaded a ShaderGraphMaterial from a RealityKit content bundle and I'm attempting to access the initial values of its parameters using getParameter(handle:), but this method appears to always return nil:

let shaderGraphMaterial = try await ShaderGraphMaterial(named: "MyMaterial", from: "MyFile")
        
let namedParameterValue = shaderGraphMaterial.getParameter(name: "myParameter")

// This prints the value of the `myParameter` parameter, as expected.
print("namedParameterValue = \(namedParameterValue)")

let handle = ShaderGraphMaterial.parameterHandle(name: "myParameter")
let handleParameterValue = shaderGraphMaterial.getParameter(handle: handle)

// Expected behavior: prints the value of the `myParameter` parameter, as above.
// Observed behavior: prints `nil`.
print("handleParameterValue = \(handleParameterValue)")

Is this expected behavior?

Based on the documentation at https://developer.apple.com/documentation/realitykit/shadergraphmaterial/getparameter(handle:) I'd expect getParameter(handle:) to return the value of the parameter, just as getParameter(name:) does.

I've tested this on iOS 18.5 and iOS 26.0 beta 2.

Assuming this getParameter(handle:) works as designed, is the following ShaderGraphMaterial extension an appropriate workaround, or can you recommend a better approach?

Thank you.

public extension ShaderGraphMaterial {

    /// Reassigns the values of all named material parameters using the handle-based API.
    ///
    /// This works around an issue where, at least as of RealityKit 26.0 beta 2 and
    /// earlier, `getParameter(handle:)` will always return `nil` when used to read the
    /// initial value of a shader graph material parameter read using
    /// `ShaderGraphMaterial(named:from:in:)`, whereas `getParameter(name:)` will work
    /// as expected.
    private mutating func copyNamedParametersToHandles() {
        for parameterName in self.parameterNames {
            if let value = self.getParameter(name: parameterName) {
                let handle = ShaderGraphMaterial.parameterHandle(name: parameterName)
                do {
                    try self.setParameter(handle: handle, value: value)
                } catch {
                    assertionFailure("Cannot set parameter value")
                }
            }
        }
    }

}
Answered by Vision Pro Engineer in 846812022

Hi @drewolbrich

This is an issue we're aware of, so your current workaround using the getParameter(name:) method instead looks appropriate for now.

Even though we're aware of this issue, we still encourage you to open a bug report, and post the FB number here once you do. The specific info you include with your bug report might help our investigation, and by filing the bug report you'll get notified when it is resolved.

Bug Reporting: How and Why? explains how you can open a bug report.

Thanks!

Accepted Answer

Hi @drewolbrich

This is an issue we're aware of, so your current workaround using the getParameter(name:) method instead looks appropriate for now.

Even though we're aware of this issue, we still encourage you to open a bug report, and post the FB number here once you do. The specific info you include with your bug report might help our investigation, and by filing the bug report you'll get notified when it is resolved.

Bug Reporting: How and Why? explains how you can open a bug report.

Thanks!

ShaderGraphMaterial.getParameter(handle:) always return nil, is this expected behavior?
 
 
Q