# Swift test + RealityKit custom component decode mismatch (has == true, typed decode == nil) — minimal repro

**URL:** <https://forums.swift.org/t/swift-test-realitykit-custom-component-decode-mismatch-has-true-typed-decode-nil-minimal-repro/84937>\
**Category:** Package Manager\
**Tags:** packagemanager, testing, xcodebuild, swift-testing, realitykit\
**Created:** [February 23, 2026, 11:29pm UTC](https://forums.swift.org/t/swift-test-realitykit-custom-component-decode-mismatch-has-true-typed-decode-nil-minimal-repro/84937 "2026-02-23T23:29:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mesqueeb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mesqueeb/32/35666_2.png) [@mesqueeb](https://forums.swift.org/u/mesqueeb)\
**Post date:** [February 23, 2026, 11:29pm UTC](https://forums.swift.org/t/swift-test-realitykit-custom-component-decode-mismatch-has-true-typed-decode-nil-minimal-repro/84937/1 "2026-02-23T23:29:05Z")

</div>

Hi all,

I’m seeing what looks like a mismatch specifically when running tests via SwiftPM CLI (`swift test`), and I’m not sure whether this should be tracked as SwiftPM, Swift Testing, or RealityKit.

I made a minimal repro repo:  
[https://github.com/mesqueeb/swiftpm-realitykit-custom-component-repro](https://github.com/mesqueeb/swiftpm-realitykit-custom-component-repro)

It’s intentionally tiny:

- one custom RealityKit component (`ReproComponent`)
- one tiny local USDA file with that custom component attached
- one test that loads the entity and checks raw-vs-typed component access

Repro command:

```bash
swift test --filter componentsPresentButNotDecodableInSwiftTest

```

Observed:

- `entity.components.has(ReproComponent.self) == true`
- `entity.components[ReproComponent.self] == nil`
- test reports `raw=1`, `decoded=0`

Expected:

- if `has(...)` is true for that registered custom component, typed lookup should decode and return non-nil.

In my main project, this difference affects E2E behavior, and running via `xcodebuild test` appears to behave differently from `swift test`.

Question:

- Is this best reported/triaged from the SwiftPM side, or should I file/move this directly as a RealityKit issue (Feedback Assistant)?
- Any known constraints around custom component decoding in SwiftPM test runtime?

Thanks for any guidance.

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [February 24, 2026, 12:29am UTC](https://forums.swift.org/t/swift-test-realitykit-custom-component-decode-mismatch-has-true-typed-decode-nil-minimal-repro/84937/2 "2026-02-24T00:29:06Z")

</div>

I don't see anything here that suggests a bug in Swift Testing. While it may be a bug in SwiftPM (I'm not an expert on that part of it) I would start by filing feedback against RealityKit with Apple about it. If it does turn out to be a SwiftPM issue, they can send the bug report along.

---

<div class="post-metadata">

**Author:** ![mesqueeb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mesqueeb/32/35666_2.png) [@mesqueeb](https://forums.swift.org/u/mesqueeb)\
**Post date:** [March 2, 2026, 12:57am UTC](https://forums.swift.org/t/swift-test-realitykit-custom-component-decode-mismatch-has-true-typed-decode-nil-minimal-repro/84937/3 "2026-03-02T00:57:40Z")

</div>

Submitted as FB22099519.  
I never know why people post these though, as I'm pretty sure it's not possible to make the ticket "public". 🤔

---

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [March 2, 2026, 6:36am UTC](https://forums.swift.org/t/swift-test-realitykit-custom-component-decode-mismatch-has-true-typed-decode-nil-minimal-repro/84937/4 "2026-03-02T06:36:18Z")

</div>

It helps other people file similar reports, they can then reference this number.

---

<div class="post-metadata">

**Author:** ![mesqueeb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mesqueeb/32/35666_2.png) [@mesqueeb](https://forums.swift.org/u/mesqueeb)\
**Post date:** [April 8, 2026, 6:25pm UTC](https://forums.swift.org/t/swift-test-realitykit-custom-component-decode-mismatch-has-true-typed-decode-nil-minimal-repro/84937/5 "2026-04-08T18:25:12Z")

</div>

I can't find where to edit the original post.

I wanted to edit to clarify, as I think the message is a bit unclear.

In just 3 lines, the issue boils down to this:

* * *

When a custom RealityKit component is present (eg. `ReproComponent`) in swift testing we observe:

- ✅ `entity.components.has(ReproComponent.self)` → `true`
- ❌ `entity.components[ReproComponent.self]` → `nil`  
(expected: a `ReproComponent` value)

* * *

that's the bug

---

<div class="post-metadata">

**Author:** ![mesqueeb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mesqueeb/32/35666_2.png) [@mesqueeb](https://forums.swift.org/u/mesqueeb)\
**Post date:** [September 19, 2026, 7:17pm UTC](https://forums.swift.org/t/swift-test-realitykit-custom-component-decode-mismatch-has-true-typed-decode-nil-minimal-repro/84937/6 "2026-09-19T19:17:37Z")

</div>

Update, six months on: this still reproduces on macOS 27.0 (26A428) and it has escalated from a wrong result to a crash.

Running the same repro package now terminates with SIGSEGV instead of failing the expectation. The faulting frames are all inside RealityKit's USD importer, re-encoding the component it just created:

```swift
Foundation JSONWriter.serializeString(_:)
RealityFoundation encodeComponent(_:_:_:)
CoreRE convertToEntityAssetData(...)
CoreRealityIO StageSceneLibraryAssetBuilder::run

```

Two findings that change the framing of this thread:

1. It is not SwiftPM-specific. A single Swift file with no package, bundle or test framework crashes the same way: register a `Codable` component with a `String` field, write a `.usda` with a matching `RealityKitCustomComponent` prim, and call `Entity(contentsOf:)`. It also crashes under `xcodebuild test` when the raw `.usda` is in the bundle.

2. The component instance is uninitialized memory, not a failed decode. Swap the `String` for a `Float` and the load succeeds, `has` is true, and the typed lookup returns `-4.170893e+07` rather than the USD value or the Swift default. A `String` made of arbitrary bytes crashes on first read, which is what the "has == true, typed == nil" symptom on macOS 26 was hiding.

The reason `xcodebuild test` looked fine in a real project is that Reality Composer Pro compiles `.rkassets` into a `.reality` file, which never goes through the USD importer. `swift test` ships the raw USD instead. Loading the same content compiled with `xcrun realitytool compile` works under `swift test` too, so that's a workaround if anyone needs SwiftPM in the meantime.

Filed as FB24852723 with the single-file repro and crash report. @grynspan was right that this belongs with RealityKit rather than SwiftPM or Swift Testing.
