# Why does UsdImagingSelectionSceneIndex::GetPrim() add a selection data source to all prims?

**URL:** <https://forum.aousd.org/t/why-does-usdimagingselectionsceneindex-getprim-add-a-selection-data-source-to-all-prims/834>\
**Category:** Hydra\
**Created:** [October 20, 2023, 3:28pm UTC](https://forum.aousd.org/t/why-does-usdimagingselectionsceneindex-getprim-add-a-selection-data-source-to-all-prims/834 "2023-10-20T15:28:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ppt-adsk](https://avatars.discourse-cdn.com/v4/letter/p/f4b2a3/32.png) [@ppt-adsk](https://forum.aousd.org/u/ppt-adsk)\
**Post date:** [October 20, 2023, 3:28pm UTC](https://forum.aousd.org/t/why-does-usdimagingselectionsceneindex-getprim-add-a-selection-data-source-to-all-prims/834/1 "2023-10-20T15:28:58Z")

</div>

> <https://github.com/PixarAnimationStudios/OpenUSD/blob/db8d57d59ccb143e4b04922bad545f36cbcfba1e/pxr/usdImaging/usdImaging/selectionSceneIndex.cpp#L841>

seems to add a selection data source to all (valid) scene index prims. Why is that? My expectation would be that only selected scene index prims would need this. Thanks for any help.

Pierre

---

<div class="post-metadata">

**Author:** ![tomc](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@tomc](https://forum.aousd.org/u/tomc)\
**Post date:** [November 18, 2023, 12:40am UTC](https://forum.aousd.org/t/why-does-usdimagingselectionsceneindex-getprim-add-a-selection-data-source-to-all-prims/834/2 "2023-11-18T00:40:19Z")

</div>

Hi Pierre,

The selection scene index will perform a map on every prim, but the map is evaluated (and potentially re-evaluated) lazily, and refers to the selection state. If you look up a bit: [https://github.com/PixarAnimationStudios/OpenUSD/blob/0b18ad3f840c24eb25e16b795a5b0821cf05126e/pxr/usdImaging/usdImaging/selectionSceneIndex.cpp#L191](https://github.com/PixarAnimationStudios/OpenUSD/blob/0b18ad3f840c24eb25e16b795a5b0821cf05126e/pxr/usdImaging/usdImaging/selectionSceneIndex.cpp#L191) … in \_PrimSource, you can see that if the prim is selected, we overlay a “selections” datasource onto it; and if not, we just pass through to the underlying scene data.

Hope that clarifies!  
Tom
