Why is my pointer array not saving when I relaunch editor?

I save my asset but when I reload editor than my data is not saved. I need to save these nodes for runtime use.



void FluidNarratorGraphEditor::SaveAsset_Execute()
{
if (Graph->IsAsset())
UFluidNarratorEditorUtilities::SaveGraphAsset(Graph);

TArray<UPackage*> PackagesToSave;
PackagesToSave.Add(Graph->GetPackage());
FEditorFileUtils::PromptForCheckoutAndSave(PackagesToSave,true,false);
}




UCLASS(Blueprintable)
class FLUIDNARRATORRUNTIME_API UFluidNarratorGraph : public UObject
{
GENERATED_BODY()

public:

UPROPERTY(EditAnywhere)
TArray<UFluidNarratorGraphNode*> Nodes;

#if WITH_EDITORONLY_DATA
UPROPERTY()
class UEdGraph* EdGraph;
#endif
};



When I use my save code

When I relaunch the editor.

Could be serialization issue, where the pointers aren’t being ‘saved’ correctly. It could also be a deserialization issue, where the TArray is initialized before the nodes exist, resultng in the entries becoming null pointers(“None”). Just some guesses.

Thanks Tulpuh. I did not fix the issue as is but I did something else that works. I also see a big speed increase in opening the asset and saving it. I think its because now I am just using structs with no pointers per node. I think it was the fact I did not put Instanced tag in UPROPERTY. By the time I found that tag I already changed how my node data is. Its going to be a bit more work to write runtime controller for graph sine I am not using pointers but I did this same method in Unity so I am confident it will work out.


USTRUCT(BlueprintType)
struct FFluidNarratorGraphNode
{
GENERATED_USTRUCT_BODY()

UPROPERTY(EditAnywhere, BlueprintReadWrite)
FGuid Guid;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FGuid> LinksByUID;
UPROPERTY(Instanced, EditDefaultsOnly)
UFluidNarratorGraphNodeEffect* NodeEffect;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FFluidNarratorGraphNodeTransitData Transit;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float LocationX;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float LocationY;
};




UCLASS(Blueprintable, BlueprintType)
class FLUIDNARRATORRUNTIME_API UFluidNarratorGraph : public UObject
{
GENERATED_BODY()

public:

UPROPERTY(EditAnywhere, BlueprintReadOnly)
TArray<FFluidNarratorGraphNode> Nodes;
};

Yeah we’ve run into this before as well. If you want to save an array into the level, everything in the array must be a serializable UObject with UPROPERTY() tag. (AFAIK)

Our approach was similar … to make a struct with the proper UPROPERTY() references.

Good To know for the future. Hopefully this post helps someone else in the future.

1 Like