I have a custom plugin that adds an Actor to a level using AddActor. When I try and save the level after the add I get the following message…
Can't save ../../../../../../WorkingDir/ArcadeDungeon/Content/Maps/Test_Example/Test_Example.umap: Graph is linked to private object(s) in an external package.
External Object(s):
MaterialInstanceDynamic_0
Try to find the chain of references to that object (may take some time)?
From testing around, the issue is because of the UDynamicMaterialInstance being attached to the static mesh. If I set the material directly (and don’t create a dynamic version) it all works and saves fine.
Code:
//.h
UCLASS()
class APolygonalGridData : public AActor
{
GENERATED_BODY()
public:
APolygonalGridData();
protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
class UStaticMeshComponent* MeshComponent = NULL;
}
//.cpp
APolygonalGridData::APolygonalGridData()
{
static ConstructorHelpers::FObjectFinder<UMaterial> M_WorldSpaceGrid(TEXT("Material'/PolygonalGrid/Materials/M_WorldSpaceGrid'"));
FINDER<UStaticMesh> SM_Plane(TEXT("Material'/Engine/BasicShapes/Plane'"));
PrimaryActorTick.bCanEverTick = false;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComponent"));
MeshComponent->SetupAttachment(RootComponent);
MeshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
if (SM_Plane.Succeeded())
{
MeshComponent->SetStaticMesh(SM_Plane.Object);
}
if (M_WorldSpaceGrid.Succeeded())
{
MeshComponent->SetMaterial(0, UMaterialInstanceDynamic::Create(M_WorldSpaceGrid.Object, MeshComponent));
}
}