Can't save map, graph is linked to external private object(s)

I created an actor that procedural adds components in its constructor, but when I place it in the level I lose the ability to save the map. The components are added to an array of structs, with one of the members in the struct being the component pointer.

The relevant parts of the code follow

 struct FGridVoxel
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voxels")
         UPrimitiveComponent* Component;
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voxels")
         int32 X;
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voxels")
         int32 Y;
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voxels")
         int32 Z;
         X = 0;
         Y = 0;
         Z = 0;
         Component = NULL;
     FGridVoxel(UPrimitiveComponent* Comp, int32 x, int32 y, int32 z)
         X = x;
         Y = y;
         Z = z;
         Component = Comp;
 //From the constructor
 int32 X = BoxExtent.X / VoxelExtent.X;
     int32 Y = BoxExtent.Y / VoxelExtent.Y;
     int32 Z = BoxExtent.Z / VoxelExtent.Z;
     //Populate the volume with voxels
     for (int32 x = -X; x <= X; x++)
         for (int32 y = -Y; y <= Y; y++)
             for (int32 z = -Z; z <= Z; z++)
                 int32 N = Grid->Voxels.Num();
                 FString Name = "Voxel_" + FString::FromInt(N);
                 UBoxComponent* NewVox = NewObject<UBoxComponent>(this, FName(*Name));
                 NewVox->bGenerateOverlapEvents = true;
                 Grid->AddVoxel(NewVox, x, y, z);
 //Add voxel function
 int32 UVoxelGridComponent::AddVoxel(UPrimitiveComponent* Comp, int32 X, int32 Y, int32 Z)
     FGridVoxel NewVox = FGridVoxel(Comp, X, Y, Z);
     Comp->AttachToComponent(this, FAttachmentTransformRules::SnapToTargetIncludingScale);
     Comp->SetRelativeLocation(RelativeFromAddress(X, Y, Z));
     return Voxels.Add(NewVox);

hard to tell, would you please post a screenshot of your code so we can assist you better? Thank you :slight_smile:

For some reason I had to post as an answer instead of as a comment.

there is an edit option under the post you can change it to comment

Then edit your original post, and add the code to it

It says it is too long to convert to a comment.

I’m not 100% sure, but that bug. When i’m adding component to my actor with NewObject<>() I’m lose the ability to save the map too.

Try this:

  1. Remove this object from scene.
  2. Comment line 53 and some another (that there was no compile errors).
  3. Compile.
  4. Place object to the scene and save. In my case editor show no errors.
  5. Uncomment lins.
  6. Compile again.
  7. Change somethings on scene and save.

So, in my case this solution helps. But, if you place this object to the scene again this “saving bug” returns.
Sorry for my english and have a nice day!

Ok, I found another way:

  1. In header make:
    UBoxComponent* NewVox;
  2. In .cpp use NewVox = NewObject(this, FName(*Name));

Just in case remove Intermediate, Binaries, Saved and generate VS project files agine. In my case solution helps after these steps.

I am getting the same potential bug as mentioned here.

			UArrowComponent *arrow = NewObject<UArrowComponent>(this);
			arrow->AttachToComponent(this, FAttachmentTransformRules::KeepRelativeTransform);

I create components in the PostEditChangeProperty() event and add them to an array I manage (destroying before recreating them again). Everything works fine and as expected (I think), except I can no longer save the map that has this component.

I worked on this bug now all day with a custom component and the thing (I think) that solved it was that you should not use NewObject but to use the

  ATest::ATest(const FObjectInitializer& ObjectInitializer):Super(ObjectInitializer){

constructor and then use

ObjectInitializer.CreateDefaultSubobject <UTest> (this, TEXT("Test"), true);

to create the object. at least that’s what fixed it for me.