[Tutorial] UE5 Add Reimport Support to Custom Asset

Advertisement

In this tutorial, we will cover adding reimport functionality to overwrite existing custom assets in unreal engine. We assume that at this point you have a custom asset created using UFactory and we will be continuing from there. This is an extension of how to create a custom asset type in unreal engine tutorial. We have defined a key variable for file path in that tutorial and we assume you have that variable in your UFactory child class.

1.Inherit from FReimportHandler class

The first thing you want to do is extend your custom UFactory child and inherit from FReimportHandler class. This class will add support to handle all the reimport functionality for our custom asset. My preferred way to do this is with multiple inheritance. That is; inherit from both UFactory and FReimportHandler classes at the same time like this: 

				
					UCLASS()
class UBcgAssetFactory : public UFactory , public FReimportHandler
{
        //Function Overrides here;
}
				
			

2. Override FReimportHandler Virtual Functions

There are 3 key virtual functions that need to be overridden in order to support Reimport functionality for your custom asset. These are:

The CanReimport() function, returns a bool to signal if the asset can be reimported or not.

The SetReimportPaths() function, sets the new paths. 

The Reimport() function, is the actual implementation of the importation process.

				
						//Should return true
	virtual bool CanReimport(UObject* Obj, TArray<FString>& OutFilenames)  override;

	virtual void SetReimportPaths(UObject* Obj, const TArray<FString>& NewReimportPaths) override;

	virtual EReimportResult::Type Reimport(UObject* Obj) override;
				
			

a. The SetReimportPaths() function

This function is called before the Reimport function. When a user clicks the “Reimport” button, unreal engine will present them with a dialog to select a file. It could be any file, meaning a different file on disk apart from the original used to create the initial asset. Maybe the original was renamed.

The variable NewImportPaths gives the developer a chance to do something with the newly selected file’s path. In our case, it gives us the chance to change SourceBcgFile(path) to the newly selected file path. Don’t get confused by the array, just select the first element [0] if you’re expecting one file to be selected. Obj is the uasset to update.

b. The Reimport function

The Obj* variable throughout these virtual functions is our uasset, the old one that we are trying to overwrite.  Now, after SetReimportPaths function, unreal engine will call the Reimport function with the Obj that we just updated in SetReimportPaths(). The update we made in that object is that we updated the file paths variable; SourceBcgFile. We are going to use this new path in the Reimport function.

Specifically, we are going to call ImportObject with this new path that we got from SetReimportPaths. 

Unreal engine will then call FactoryCreateFile()…  The overridden method we created in the initial tutorial create a custom asset tutorial. The import and reimport process is now complete.

The Reimport Button

There will be a reimport button when you double-click your asset and open its asset editor. You’ll find it on the top menu of the asset under the “Asset” submenu. We prefer our reimport button on the right-click menu but we don’t cover it in this tutorial. For that, you can read the how-to add reimport button to the right-click menu of a custom asset tutorial.

Conclusion

If you have questions and comments feel free to email us. We hope you check out our Plugin Development Course for unreal engine first though, whatever we may have skipped in these tutorials, it’s definitely covered in the video in the course.

5/5

Gamechanger plugin for notehighway rhythm games and music visualizers

5/5

Add Text and 2D UMG widgets to Level Sequences

Consider investing in some of our plugins. They might save you some time.  Also helps supports these tutorials.

Instantly get access to our plugins like Blender Curves Importer and UMG Cinematics and more when  you support us on Patreon!

 Join Us On Discord For More Daily Tips!