Highlight or select entity in RealityKit

I'm in the process of converting my SceneKit game to RealityKit. In SceneKit I used to be able to mark nodes as selected by setting SCNMaterial.emission with a custom color. I can do the same with PhysicallyBasedMaterial.emissiveColor, but I'd like to keep my entitities unaffected by the scene lights by using UnlitMaterial. In SceneKit I can set a category mask to indicate what light should affect what node, but there doesn't seem to be such a thing in RealityKit. So at the moment it seems like I have to choose between being able to mark an entity as selected, or having entities unaffected by lighting, but not both.

Is there some effect or component I can use to mark entities as selected by applying some coloring regardless of the material used?

Answered by DTS Engineer in 878400022

You're correct about this difference between frameworks. RealityKit doesn't offer light category masks like SceneKit does.

For highlighting entities with UnlitMaterial, consider these approaches:

  • Create a selection component that swaps between regular and highlighted versions of your materials
  • Add a thin highlight mesh as a child entity when selected (like an outline)
  • Use ModelEntity.model?.materials.enumerated() to temporarily replace materials during selection

The UnlitMaterial intentionally ignores lighting completely, so you'll need one of these workarounds rather than relying on emission effects for selection highlighting.

You're correct about this difference between frameworks. RealityKit doesn't offer light category masks like SceneKit does.

For highlighting entities with UnlitMaterial, consider these approaches:

  • Create a selection component that swaps between regular and highlighted versions of your materials
  • Add a thin highlight mesh as a child entity when selected (like an outline)
  • Use ModelEntity.model?.materials.enumerated() to temporarily replace materials during selection

The UnlitMaterial intentionally ignores lighting completely, so you'll need one of these workarounds rather than relying on emission effects for selection highlighting.

Thanks for your suggestions.

  • When swapping materials, is it possible to do so with an animation?
  • When adding a highlight mesh, is there a preferred way? I tried creating an entity with the same mesh but a slightly larger scale and some opacity, but this doesn't work when the mesh is two-dimensional (e.g. a card), for which an increased scale only moves the vertices away from its center for two out of three dimensions, so the two meshes overlap in the third dimension creating rendering artefacts.
Highlight or select entity in RealityKit
 
 
Q