diff --git a/Source/CesiumRuntime/Private/Cesium3DTileset.cpp b/Source/CesiumRuntime/Private/Cesium3DTileset.cpp index bb8afd695..50b5324ab 100644 --- a/Source/CesiumRuntime/Private/Cesium3DTileset.cpp +++ b/Source/CesiumRuntime/Private/Cesium3DTileset.cpp @@ -12,6 +12,7 @@ #include "Cesium3DTilesSelection/TilesetOptions.h" #include "Cesium3DTilesetLoadFailureDetails.h" #include "Cesium3DTilesetRoot.h" +#include "CesiumActors.h" #include "CesiumAsync/IAssetResponse.h" #include "CesiumBoundingVolumeComponent.h" #include "CesiumCamera.h" @@ -2087,6 +2088,8 @@ void ACesium3DTileset::PostLoad() { // actor to have correct BodyInstance values. Super::PostLoad(); + + CesiumActors::validateActorFlags(this); } void ACesium3DTileset::Serialize(FArchive& Ar) { diff --git a/Source/CesiumRuntime/Private/CesiumActors.cpp b/Source/CesiumRuntime/Private/CesiumActors.cpp index c8c212478..03fb9fe6b 100644 --- a/Source/CesiumRuntime/Private/CesiumActors.cpp +++ b/Source/CesiumRuntime/Private/CesiumActors.cpp @@ -23,3 +23,35 @@ glm::dvec4 CesiumActors::getWorldOrigin4D(const AActor* actor) { const FIntVector& originLocation = world->OriginLocation; return glm::dvec4(originLocation.X, originLocation.Y, originLocation.Z, 1.0); } + +void CesiumActors::validatePublicFlag(UObject* object, const FString& label) { + // + // From an Epic Engine Developer... + // RF_Public means that the object is an asset, so it should be only set for + // worlds, textures, meshes, etc. This flags essentially says it's ok to + // have a reference to public objects from other packages (with the + // exception of worlds). Actors are not assets since they are part of a + // level which is part of a world, etc. that's why they should not key the + // public flag. + // + // In earlier versions of cesium-unreal, this flag may have been set + // + if (object->HasAnyFlags(RF_Public)) { + UE_LOG( + LogCesium, + Display, + TEXT("Clearing invalid RF_Public flag on %s"), + *label); + object->ClearFlags(RF_Public); + } +} + +void CesiumActors::validateActorFlags(AActor* actor) { + FString label = FString("actor: ") + *actor->GetName(); + validatePublicFlag(actor, label); +} + +void CesiumActors::validateActorComponentFlags(UActorComponent* component) { + FString label = FString("actor component: ") + *component->GetName(); + validatePublicFlag(component, label); +} diff --git a/Source/CesiumRuntime/Private/CesiumActors.h b/Source/CesiumRuntime/Private/CesiumActors.h index 23ff60f45..960876e3a 100644 --- a/Source/CesiumRuntime/Private/CesiumActors.h +++ b/Source/CesiumRuntime/Private/CesiumActors.h @@ -28,4 +28,10 @@ class CesiumActors { * @return The world origin */ static glm::dvec4 getWorldOrigin4D(const AActor* actor); + + static void validateActorFlags(AActor* actor); + static void validateActorComponentFlags(UActorComponent* component); + +private: + static void validatePublicFlag(UObject* object, const FString& label); }; diff --git a/Source/CesiumRuntime/Private/CesiumCartographicPolygon.cpp b/Source/CesiumRuntime/Private/CesiumCartographicPolygon.cpp index 925090845..19489b772 100644 --- a/Source/CesiumRuntime/Private/CesiumCartographicPolygon.cpp +++ b/Source/CesiumRuntime/Private/CesiumCartographicPolygon.cpp @@ -1,6 +1,7 @@ // Copyright 2020-2021 CesiumGS, Inc. and Contributors #include "CesiumCartographicPolygon.h" +#include "CesiumActors.h" #include "CesiumUtility/Math.h" #include "Components/SceneComponent.h" #include "StaticMeshResources.h" @@ -79,3 +80,9 @@ void ACesiumCartographicPolygon::MakeLinear() { this->Polygon->SetSplinePointType(i, ESplinePointType::Linear); } } + +void ACesiumCartographicPolygon::PostLoad() { + Super::PostLoad(); + + CesiumActors::validateActorFlags(this); +} diff --git a/Source/CesiumRuntime/Private/CesiumIonRasterOverlay.cpp b/Source/CesiumRuntime/Private/CesiumIonRasterOverlay.cpp index 6657d9d0f..7eb927a5a 100644 --- a/Source/CesiumRuntime/Private/CesiumIonRasterOverlay.cpp +++ b/Source/CesiumRuntime/Private/CesiumIonRasterOverlay.cpp @@ -3,6 +3,7 @@ #include "CesiumIonRasterOverlay.h" #include "Cesium3DTilesSelection/IonRasterOverlay.h" #include "Cesium3DTilesSelection/Tileset.h" +#include "CesiumActors.h" #include "CesiumRuntime.h" #include "CesiumRuntimeSettings.h" @@ -36,3 +37,9 @@ UCesiumIonRasterOverlay::CreateOverlay( TCHAR_TO_UTF8(*token), options); } + +void UCesiumIonRasterOverlay::PostLoad() { + Super::PostLoad(); + + CesiumActors::validateActorComponentFlags(this); +} diff --git a/Source/CesiumRuntime/Public/CesiumCartographicPolygon.h b/Source/CesiumRuntime/Public/CesiumCartographicPolygon.h index 6a8d0acc8..76a89a0e1 100644 --- a/Source/CesiumRuntime/Public/CesiumCartographicPolygon.h +++ b/Source/CesiumRuntime/Public/CesiumCartographicPolygon.h @@ -51,6 +51,9 @@ class CESIUMRUNTIME_API ACesiumCartographicPolygon : public AActor { CesiumGeospatial::CartographicPolygon CreateCartographicPolygon(const FTransform& worldToTileset) const; + // AActor overrides + virtual void PostLoad() override; + protected: virtual void BeginPlay() override; diff --git a/Source/CesiumRuntime/Public/CesiumIonRasterOverlay.h b/Source/CesiumRuntime/Public/CesiumIonRasterOverlay.h index 909b8641e..8773baf03 100644 --- a/Source/CesiumRuntime/Public/CesiumIonRasterOverlay.h +++ b/Source/CesiumRuntime/Public/CesiumIonRasterOverlay.h @@ -50,6 +50,9 @@ class CESIUMRUNTIME_API UCesiumIonRasterOverlay : public UCesiumRasterOverlay { UFUNCTION(CallInEditor, Category = "Cesium") void TroubleshootToken(); + // UActorComponent overrides + virtual void PostLoad() override; + protected: virtual std::unique_ptr CreateOverlay( const Cesium3DTilesSelection::RasterOverlayOptions& options = {})