Metadata Components Not Found via Raycast

Hi,

I’m working on a project using Cesium for Unity to create a thermal simulation effect based on surface type metadata. I’m running into an issue where I cannot seem to access the metadata via raycasting.

Setup:

  • Built-in RP
  • Unity 2022.3.32f1
  • Cesium 1.15.5 (Installed via .tgz)
  • Datasets: Cesium World Terrain + Bing Maps Aerial and Cesium OSM Buildings (both added via Cesium ion Assets)

Goal:
I want to perform a raycast from my camera, hit Cesium geometry (specifically OSM Buildings or Terrain), identify the type of surface hit using metadata properties (like “building”, “highway”, “surface”, “natural”), and use that information to determine a temperature value for my thermal visualization. Ideally I want to store object types (road, grass, buildings, etc.) and their associated temperatures so I can automatically render a thermal version of the Cesium geometry using these temperatures.

Problem:
My raycast (Physics.Raycast) successfully hits the geometry generated by Cesium (e.g., objects named “Mesh 0 Primitive 0”). However, my C# script fails to get the necessary metadata components from the hit object.

Specifically, calls like hit.transform.GetComponent<CesiumPrimitiveFeatures>() and hit.transform.GetComponentInParent<CesiumModelMetadata>() consistently return null.

The console log typically shows: Ray hit: Mesh 0 Primitive 0 at distance X CesiumPrimitiveFeatures NOT found on hit transform. CesiumModelMetadata NOT found on hit transform or parents. Using default temp.

Relevant Code:

// Inside a method processing RaycastHit hit:
// Using statements: using CesiumForUnity; using System; using System.Collections.Generic;

CesiumPrimitiveFeatures features = hit.transform.GetComponent<CesiumPrimitiveFeatures>();
CesiumModelMetadata metadata = hit.transform.GetComponentInParent<CesiumModelMetadata>();

if (features != null && metadata != null && features.featureIdSets != null && features.featureIdSets.Length > 0)
{
    // Logic to get feature ID and properties (adapted from sample)
    // ... this part is never reached because features or metadata is null ...
    Debug.Log("Found Cesium Components!"); // This log never appears
}
else
{
    // These logs consistently appear:
    if(features == null) Debug.LogWarning("CesiumPrimitiveFeatures NOT found on hit transform.");
    if(metadata == null) Debug.LogWarning("CesiumModelMetadata NOT found on hit transform or parents.");
}

Is there a specific setting I might be missing on the Cesium3DTileset (especially for OSM Buildings) in Cesium for Unity v1.15.5 that is required to generate/attach the CesiumPrimitiveFeatures and CesiumModelMetadata components at runtime? Or is there a known limitation or different API approach needed for accessing feature metadata in this version with the Built-in Render Pipeline?

Any help would be greatly appreciated! Thanks!

Hi @sharanyap21, welcome to the community!

Thank you for the detailed write-up. We actually have a level for this in our Cesium for Unity Samples called 05_CesiumMetadata, which includes a script for metadata picking. Could you verify if that works for you? If so, you’re welcome to use the script as a starting point for your project. :smile: