Component with SIMD3<Float>

I want to use SIMD values with a design time component.

public struct SomeComponent: Component, Codable { public var Magnitude: SIMD3<Float> = .zero
}

Is extra work required? I had understood that serialization of simple values including SIMD would be handled by Reality Composer Pro.

At run time I get the error:

decodeComponent: Unexpected error: keyNotFound(CodingKeys(stringValue: "Magnitude", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: "Magnitude", intValue: nil) ("Magnitude").", underlyingError: nil)) Asset deserialization failed. Asset type "SceneAsset". Details: Failed to deserialize "/container/@shared/17/object". Reason: Failed to deserialize Swift Codable component of type RealityKitContent.SomeComponent.

Answered by Vision Pro Engineer in 802671022

Hi @matthewfromkaty

There are two workarounds you can try. The first would be to initialize any SIMD3<Float> using an array literal. That means instead of initializing with .zero , use [0, 0, 0] like this:

public var Magnitude: SIMD3<Float> = [0, 0, 0]

Your second option is to make the property optional:

public var Magnitude: SIMD3<Float>? = .zero

Either of these workarounds should solve your issue. Let me know if this helps!

Accepted Answer

Hi @matthewfromkaty

There are two workarounds you can try. The first would be to initialize any SIMD3<Float> using an array literal. That means instead of initializing with .zero , use [0, 0, 0] like this:

public var Magnitude: SIMD3<Float> = [0, 0, 0]

Your second option is to make the property optional:

public var Magnitude: SIMD3<Float>? = .zero

Either of these workarounds should solve your issue. Let me know if this helps!

Thank you! The array literal worked for me yay!

Component with SIMD3&lt;Float&gt;
 
 
Q