About how to get the UCustomCesiumGeoJsonOverlay by C++

Hello everyone, I’m using Cesium for Unreal with C++ to build a scene. I upload a GeoJSON file to add an overlay to a Cesium3DTileset, but when I click the overlay, I can’t retrieve the UCustomCesiumGeoJsonOverlay information.

Hey @libo19921114, welcome to the forum! Thanks for sharing the code, that helps a lot.

I think I can see the issue. The line trace hit component (HitResult.GetComponent()) on line 156 returns the mesh primitive component that was physically hit. This is a UCesiumGltfPrimitiveComponent (the rendered tile geometry), not the raster overlay. So this cast will always return null:

// This will always fail - HitComponent is a mesh, not an overlay
UCustomCesiumGeoJsonOverlay* HitOverlay = Cast<UCustomCesiumGeoJsonOverlay>(HitComponent);

Raster overlays are not individually hittable via line traces. They’re texture layers composited onto the tileset mesh at render time. You can’t determine which overlay was “clicked” from a line trace alone.

Your GetComponentByClass approach at the bottom is the correct way to get the overlay reference:

ACesium3DTileset* HitTileset = Cast<ACesium3DTileset>(HitResult.GetActor());
if (HitTileset)
{
    // This gives you the overlay component on the tileset actor
    UCesiumGeoJsonDocumentRasterOverlay* Overlay = 
        HitTileset->FindComponentByClass<UCesiumGeoJsonDocumentRasterOverlay>();
}

If you have multiple GeoJSON overlays on the same tileset and need to distinguish which one was clicked, you’d need to check the hit location against each overlay’s geographic bounds in your own logic, the raster overlay system doesn’t provide per-pixel overlay identification.

Could you share what information you’re trying to get from the overlay? If it’s feature metadata (properties from the GeoJSON), the approach would be different, you’d use UCesiumMetadataPickingBlueprintLibrary to query feature properties at the hit point.

Cheers!

darcyvdd, thanks alot, as you said, I have multiple GeoJSON overlays on the same tileset, and need to distinguish which one was clicked.The following picture is code. Can you give me some suggestion about how to fixed it.thans u!

Thanks for sharing the code! Two things:

For click identification:

The MaterialLayerKey won’t help here. It controls how overlays blend in the material graph, not click identity. And as I mentioned before, raster overlays don’t expose which one was “hit” from a line trace.

The practical approach is to work with geography. When your line trace hits the tileset:

  1. Get the hit location in world space (HitResult.ImpactPoint)
  2. Convert it to longitude/latitude using your ACesiumGeoreference actor:
    FVector LLH = Georeference->TransformUnrealPositionToLongitudeLatitudeHeight(HitResult.ImpactPoint);
    // LLH.X = longitude, LLH.Y = latitude, LLH.Z = height
    
  3. Check which Area in your list contains that geographic point

If your Area struct already carries the GeoJSON bounds you’re loading per area, you can reuse that directly. If the areas don’t overlap, a bounding box check is usually enough. If they do overlap, you’d need a point-in-polygon test against the GeoJSON geometry.