Export files to a UnityPackage file from C#

My question is very simple, I want to be able to export files from my Unity project to a UnityPackage from code, preferably C#.

This will be used for easy deployment of a tool, i am creating, to my clients.

Is this possible ?

Actually, you can use AssetDatabase.ExportPackage

You can export a .unitypackage from C# with AssetDatabase.ExportPackage

I am going to assume that you are referring to a Unity Asset Package, which uses the file extension ".unitypackage".

You actually don't need to bother with writing any code at all. Just select all of the files you want to be wrapped in the package, or just the root folder if they all share the same directory, then go to "Assets>Export Package..."

You'll get a checked list of all the files you want to include, then just hit "Export..." and you should be good to go. This is how I pass my custom script libraries around.

Hope that helps,


unfortunately there is no exposed API for this. just you can use the menu item. just for importing them you can use the -importpackage command line switch. hopefully it will be exposed in next releases. you can create a ticket in feedback for it.

I'm not sure if there are any differences between the contents of the .unitypackage and a "regular" asset bundle but another option to do this from code might be to make an exec call from your code to execute Unity on the command line.

Check out my bash script at Unity Answers and look into the Process class in C# (MSDN Page)

You can use AssetDatabase.ExportPackage as the others already said. If you want to do it without having to code but still in an automated way, have a look at the Export Unitypackage action of uTomate.