How to fix 'Failed to save' error with custom asset user data?

Hello,

I’m pretty new to Unreal, so it’s highly possible I’m doing something wrong here.

I’m getting this error:
Can't save [...]/LVL_TestSave.umap: Graph is linked to external private object MyCustomAssetUserData /Game/Blueprints/BP_Generated.BP_Generated_C:MyObject.MyCustomAssetUserData_0 (AssetUserData)
(edited with generic names).

I’ve searched online and on the forums for a solution, but anything I found either did not work, or wasn’t related to my problem.

Here is my issue: I created a custom Asset User Data class in my plugin, and when I put an auto-generated blueprint using this class in my level, I cannot save it anymore.

The file tree of the plugin looks something like this:

File Tree
PluginName/Source/PluginName/
	Private/
		PluginName.cpp
		AddAssetUserData.cpp
		GenerateBP.cpp
	Public/
		PluginName.h
		AddAssetUserData.h
		GenerateBP.h
		MyCustomAssetUserData.h
	PluginName.Build.cs

This is how I define the class:

MyCustomAssetUserData.h
// MyCustomAssetUserData.h
#pragma once

// Class includes
#include "Engine/AssetUserData.h"
#include "MyCustomAssetUserData.generated.h"


UCLASS(BlueprintType)
class UMyCustomAssetUserData : public UAssetUserData
{
	GENERATED_BODY()

public:
	UMyCustomAssetUserData()
		: Path(FString(""))
	{}

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FString Path;
};

And this is how I add the data to the scene components:

AddMyAssetUserData
template<typename T>
void AddMyAssetUserData(T* Component, FString Path) {
	UMyCustomAssetUserData* Data = NewObject<UMyCustomAssetUserData>(Component);
	Data->Path = Path;
	Component->AddAssetUserData(Data);
	Component->Modify(); // Mark as modified to make sure the changes get saved
}

I’ll explain how the error occurs:

  • When I add custom data to a scene or actor component, I can save fine.
  • When I create a BP from an actor using custom data (FKismetEditorUtilities::CreateBlueprintFromActor), I can save fine.
  • When I add the generated BP to the level, I cannot save and get the error.

Thanks in advance for the help.

When creating an object, try setting the outer parameter not to the component, but to the SCS_Node that the component belongs to.

That might work, but I ended up scrapping the asset user data idea and going for a more manual approach using tags and simple logic.

The weird thing is that I add the asset user data before creating the BP, so in theory it should already be in the SCS nodes.

It also looks like any kind of asset user data causes this issue, not just custom ones.

I had a similar problem when creating helper UObjects from Slate in FProperty.
I also had crashes after starting PIE and trying to get a reference to my created object.

By trial and error I came up with this creation:

NewObject< MyObjectClass >(GEditor, FName(“Helper”), (RF_Standalone, RF_Transient));

As you may have noticed, the owner is GEditor.
I can’t specify the slate widget as outer because it’s not a UObject, and I can’t use the blueprint where I edited the FProperty because my object is for editor only and temporary BUT it shouldn’t be deleted while the editor is open.

As I understand it, when creating an object, you need to specify the outer object, which must already exist by the time its dependent objects are needed.

Unreal has a rather peculiar way of handling components during editing, and they are re-created when compiling, so you can’t use component references directly, at least not in the cases I needed to.
Instead, you need to use a wrapper - SCS_Node, which can return the actual component.