[Editor Time] How do you save a modified asset in C++? UE4 4.22

Hi all,

Right now I’m trying to make a tool that allows me to edit a specific pawn class. I’ve made it only show the components I want to edit, a preview of the pawn, and certain properties on the currently selected component. Its basically setup like the BP editor, except its way less stuff and built using the new UEditorUtilityWidget class.

So I’m wondering now how I can save the changes made to the pawn instance of the asset into the blueprint that I’m editing. This is what my current save function looks like:

void UMyVehicleEditorUtility::SaveAsset()
{
	TArray<UPackage*> PackagesToSave;

	if (SelectedBlueprint != nullptr && SelectedBlueprint->IsAsset())
	{
		SelectedBlueprint->Modify();
		PackagesToSave.Add(SelectedBlueprint->GetOutermost());
	}
		

	FEditorFileUtils::PromptForCheckoutAndSave(PackagesToSave, bCheckDirtyOnAssetSave, 
    /*bPromptToSave=*/ false);
}

The “SelectedBlueprint” is a UBlueprint* and in the editor i’m editing an AActor*, which is spawned with this info:

FActorSpawnParameters SpawnInfo;
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
SpawnInfo.bNoFail = true;
SpawnInfo.ObjectFlags = RF_Transient | RF_Transactional;

Right now i’m just directly changing the values on the instance, so the actual UBlueprint doesn’t change. I think I need to mark the component I’m working on as “dirty” so it can mark its package as dirty, but I’ve been calling UObject::Modify() on those components and that didn’t seem to do anything.

I’ve also gone down the rabbit hole of using SKismetInspector to just create the regular details panel, but since my tool doesn’t derive from the FBlueprintEditor I don’t believe that I can use it properly. It did show up when I used it, but when I edited a property on a component, the details panel collapsed (or just went away) and when I tried saving the changes it didn’t stick.

TLDR:
How can I modify an instance of an object, during editor time, and save those changes to the blueprint (or asset)?

sorry if this wasn’t clear, but the whole saving system in UE4 seems really complicated so its hard for me to rap my head around. Thanks for reading, any help is appreciated!

Hi, I don’t know exactly. I have experienced saving utable useing GEditor->SavePackage.

2 Likes

Did you solve the problem?
I have the same issue with you.
I wanan write some data into the components which save in editor’s runtime.

Thanks, it was the way to go for me in 5.2.1!
I needed to update a DataTable. To do so:

  • load the asset via a TSoftObjectPtr<UDataTable>;
  • regenerate the content of the DataTable;
  • mark package and asset as dirty → MarkPackageDirty();
  • create save arguments with specifying SAVE_KeepDirty in the save flag
FSavePackageArgs args;
{
	args.TopLevelFlags = RF_Public | RF_Standalone;
	args.SaveFlags = SAVE_NoError | SAVE_KeepDirty;
}
  • call GEditor->SavePackage and specify the second argument, InAsset.

By doing this, the editor detects the modification and flag the asset with a “*” and warn you when you quit the editor without saving.

1 Like