GeoJsonDocumentRasterOverlay works in the Editor but fails to display when dynamically loaded via C++

I’m trying to dynamically load a ​UCesiumGeoJsonDocumentRasterOverlay​ in ​Unreal Engine (Cesium for Unreal)​​ using ​C++​, but it does not render the GeoJSON data, even though the same setup works perfectly when manually placed in the ​Editor.

I use the following code to dynamically create and attach the overlay。

ACesiumGeoreference* Georeference = ACesiumGeoreference::GetDefaultGeoreference(GetWorld());
if (!Georeference) return;

ACesium3DTileset* Tileset = FindFirstTilesetInWorld(GetWorld());
if (!Tileset) return;

UCesiumGeoJsonDocumentRasterOverlay* GeoJsonOverlay = NewObject<UCesiumGeoJsonDocumentRasterOverlay>(Tileset);
if (!GeoJsonOverlay) return;

GeoJsonOverlay->Source = ECesiumGeoJsonDocumentRasterOverlaySource::FromUrl;
GeoJsonOverlay->MaterialLayerKey = TEXT("OverlayGeoJson01");
FString Url = FString::Printf(TEXT("http://192.168.0.15:9988/gis/genGrid?centerLon=%f&centerLat=%f&spacing=%f&range=%f"),
	CenterLatitude, CenterLongitude, GridIntervalMeters, GridRangeMeters);
GeoJsonOverlay->Url = Url;
GeoJsonOverlay->DefaultStyle.LineStyle.Color = LineColor;
GeoJsonOverlay->DefaultStyle.LineStyle.Width = LineWidth;
GeoJsonOverlay->DefaultStyle.LineStyle.WidthMode = ECesiumVectorLineWidthMode::Meters;
GeoJsonOverlay->AddToTileset();
GeoJsonOverlay->Refresh();

Tileset->RefreshTileset();

This works for me:

UCesiumGeoJsonDocumentRasterOverlay* GeoJsonOverlay = NewObject<UCesiumGeoJsonDocumentRasterOverlay>(NewTileset);

if (GeoJsonOverlay)
{
    GeoJsonOverlay->Source = CesiumGeoJsonDocumentRasterOverlaySource::FromCesiumIon;
    GeoJsonOverlay->IonAssetID = ...;
    GeoJsonOverlay->RegisterComponent();
    NewTileset->AddInstanceComponent(GeoJsonOverlay);
}

RegisterComponent() automatically looks after calling AddToTileset()

Thanks, Using the method you provided. I observed that the GeoJsonOverlay can be created correctly and all parameters are accurate, but it just doesn’t show up in the scene.

When you say it works fine in the Editor, do you also use “OverlayGeoJson01” as the material layer key there? (I only ask as the material is looking for Overlay0 or Overlay1, and you’d need to change the layer parameters in the material instance if using something different.)

Thank you. It works.