Need clarifications about packages and serialization

I am currently working on a custom graph editor, taking inspiration from FSoundCueEditor and ran into this error, after calling MarkPackageDirty() on my object and then saving :

Can’t save …/…/…/…/…/…/[path_to_game_project]/LullabyGardens/Content/Lullaby/NPC/Abigail/AbigailDialogDatabase.uasset: Graph is linked to private object(s) in an external package.
External Object(s):
DialogGraph_0

I am pretty sure the error comes because of this member variable :

[NPCDialogAsset.h]
#if WITH_EDITORONLY_DATA
	UPROPERTY()
		TArray<UDialogNode*> AllNodes;

	UPROPERTY()
		class UEdGraph* DialogGraph;
#endif

I think that the reference to the graph is causing the error. I then looked at the overriden method Serialize in USoundCue, and saw that the graph is serialized with the sound cue.

I then tried to do the same thing in my version of serialize, as follows :

[NPCDialogAsset.h]
void UNPCDialogAsset::Serialize(FArchive & Ar) {
	Super::Serialize(Ar);

	if (Ar.UE4Ver() >= VER_UE4_COOKED_ASSETS_IN_EDITOR_SUPPORT)
	{
		FStripDataFlags StripFlags(Ar);
#if WITH_EDITORONLY_DATA
		if (!StripFlags.IsEditorDataStripped())
		{
			Ar << DialogGraph;
		}
#endif
	}
#if WITH_EDITOR
	else
	{
		Ar << DialogGraph;
	}
#endif
}

After changing Serialize, I couldn’t launch the editor, as the serial size with the new functions was different.

This brings me to my questions :

  1. How can I save a dirty asset that references my graph? Do I need to do call a function in the same vein as MarkPackageDirty() ?

  2. How can I override Serialize(), while avoiding the size mismatch error?

Nevermind, I managed to solve the problem by looking at SavePackage.cpp and playing around with object flags.