Hi,
I’ve tried to exclude sources of error and have got to the following state.
If I create a tileset and assign the ‘True Origin’ geolocation and globe anchor in the editor, it all works perfectly.
If I try to do the same from C++, the resulting objects have the same configuration but I cannot see the geometry. The final transform on the spawned tileset object has small differences but would still likely be visible.
If I reference a tileset with anchor created in the editor, I can give it a new source URL and update the Globe Anchor coordinates to achieve about the right result. This is good but limits creating multiple tilesets.
Spawning a geolocated tileset works fine with no additional work, no special georeference or globe anchor required, as expected.
Is there any other setting or construction order I am likely to be missing, that might explain the difference between construction in the editor and at runtime?
Thanks,
Josh
My C++ looks like so:
void ATestSpawnTileset::SpawnUnlocatedTileset(FString sourceURL, ACesiumGeoreference* mainReference, FVector lla)
{
FVector Location(0.0f, 0.0f, 0.0f);
FRotator Rotation(0.0f, 0.0f, 0.0f);
FActorSpawnParameters SpawnInfo;
UE_LOG(LogTemp, Warning, TEXT("Spawning tileset with URL %s"), *sourceURL);
ACesiumGeoreference* localReference = GetWorld()->SpawnActor<ACesiumGeoreference>(Location, Rotation, SpawnInfo);
localReference->OriginPlacement = EOriginPlacement::TrueOrigin;
localReference->SetActorLabel("BasicLocalGeoreference"); //so near top of list
ACesium3DTileset* tileset = GetWorld()->SpawnActor<ACesium3DTileset>(Location, Rotation, SpawnInfo);
tileset->GetRootComponent()->SetMobility(EComponentMobility::Movable);
tileset->SetGeoreference(localReference);
tileset->SetActorLabel(TEXT("BasicUnlocatedTileset1"));
//assigning this before setting tileset source - after behaves the same way.
UCesiumGlobeAnchorComponent* anchor = NewObject<UCesiumGlobeAnchorComponent>(tileset);
anchor->SetGeoreference(mainReference);
UE_LOG(LogTemp, Warning, TEXT("Spawning at Long %f Lat %f H %f"), lla.X, lla.Y, lla.Z);
tileset->AddInstanceComponent(anchor);
anchor->RegisterComponent();
anchor->InaccurateMoveToLongitudeLatitudeHeight(lla);
tileset->SetTilesetSource(ETilesetSource::FromUrl);
tileset->SetUrl(sourceURL);
}
void ATestSpawnTileset::ReplaceTileset(FString sourceURL, ACesium3DTileset* tileset, FVector longLatAlt)
{
tileset->GetRootComponent()->SetMobility(EComponentMobility::Movable); //should not be needed?
tileset->SetUrl(sourceURL);
FTransform transform{}; //identity
tileset->SetActorTransform(transform);
UCesiumGlobeAnchorComponent* anchor = static_cast<UCesiumGlobeAnchorComponent*>(tileset->GetComponentByClass(UCesiumGlobeAnchorComponent::StaticClass()));
if (anchor)
{
anchor->InaccurateMoveToLongitudeLatitudeHeight(longLatAlt);
}
else
{
UE_LOG(LogTemp, Error, TEXT("Missing globe anchor"));
}
}
Incidentally I don’t think I can do this via BP due to readOnly preventing setting a new Georeference to ‘TrueOrigin’ mode. C++ is needed anyway, but perhaps this is another difference between editor and runtime behaviour?
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Cesium")
EOriginPlacement OriginPlacement = EOriginPlacement::CartographicOrigin;