Programmatically Exporting an Asset Package

I would like to save the currently open scene file and all it's dependencies to a Unity Asset Package (.unitypackage) file from an Editor script.

It seems that this topic has been previously broached at , but I am posting anew to include some more ideas on the subject.

Here's a screenshot from MonoDevelop which shows some interesting functions in Unity's dll file:

And here's some code I wrote that serves to illustrate my purpose:

var guids : String[] = Array(AssetDatabase.AssetPathToGUID(EditorApplication.currentScene)).ToBuiltin(String);
UnityEditor.AssetServer.ExportPackage(guids, "/");

The code currently returns an "'AssetServer' is not a member of 'UnityEditor'" error when compiling.

Mike_Mac said that this was because the function I need to call is a private one, internal to Unity - but that I might be able to access it through reflection.

Anyone have some ideas on how this could be accomplished?

Internal things in UnityEditor/UnityEngine are internal for one of a few reasons: - it doesn't work - it only works if you use it in a very obscure way - we want to be able to change it later without breaking your game - it has some sort of security risk - we didn't realize you might actually want it

That said, you can use reflection to try to call it, but you'd be walking on very thin ice.

Unity now provides a public API that allows creating a package from a collection of assets.


It does not automatically resolves dependencies though.

PD: I think this question should be marked as a duplicate of this one And the original question should also be edited to reflect the new changes.

This might be cheesy, but what if you used Windows API functions (SendMessage and such)? Get the window handle and send the menu code that simulates you choosing the menu item.

I also need to do an export, but I can’t even use the internal one if I wanted to because it’s broken anyway. For my native os x plugins, the file extension is .bundle (as expected by unity), and the exporter for whatever reason considers these .bundle files to be empty directories, and thus cannot be selected as part of the export. So I end up having to rename the file and hack the package that’s exported. Such a pain!

I’m about to roll my own, it’s not that complicated.
The assets in the zip are not encrypted, the guids can be read from the .meta files, and the rest is pretty straight forward.

I’m not really dealing with scenes so my guids aren’t really critical anyway, but if I had to generate a guid I don’t think it would be the end of the world.