Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Aubrey-Falconer · May 02, 2010 at 01:47 AM · editor-scriptingassetexport

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 http://answers.unity3d.com/questions/3237/export-files-to-a-unitypackage-file-from-c , 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: http://img72.imageshack.us/img72/3380/screenshot20100501at556.png

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?

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cyclops · May 06, 2010 at 01:01 AM 0
Share

@Aubrey, remember to upvote good answers (and checkmark the correct one).

avatar image mlapin · Aug 13, 2010 at 04:07 PM 0
Share

Hi, doing so would be very interesting! Have you ever managed to implement it?

avatar image Aubrey-Falconer · Dec 24, 2010 at 07:15 AM 0
Share

Allright ladies and gentlemen ~ Unity 3 has come, and it has disabled reflection and added cool new API tools. I a more interested than ever in creating asset packages programatically, so please have at the bounty!

avatar image Aubrey-Falconer · Dec 30, 2010 at 06:32 AM 0
Share

Bounty ends tomorrow, everyone's suggestions are welcome

avatar image BerggreenDK · Aug 07, 2011 at 10:17 PM 0
Share

this is still only possible with the PRO editions of Unity3D, right?

Show more comments

4 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Lucas Meijer 1 · May 02, 2010 at 09:56 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Aubrey-Falconer · May 03, 2010 at 03:58 PM 0
Share

Thanks for your reply! I wouldn't at all $$anonymous$$d Unity breaking my code some time in the future - this will be a nothing more than a component of an easy-to-distribute Editor plugin, and obscurity doesn't scare me :) I have no idea how to go about using reflection, so I may have to give up on the idea for now - but if anyone would like to point my researches in the right direction, I would be most grateful.

avatar image
2

Answer by RickyAh · Feb 12, 2014 at 12:31 PM

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

UnityEditor.AssetDatabase.ExportPackage

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Art 1 · Dec 31, 2010 at 05:00 AM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Aubrey-Falconer · Dec 31, 2010 at 06:54 AM 0
Share

It brings me great pain that something as powerful as the Unity editor would have to be controlled through windows API scripting - but you're right, this may indeed be our only option at this time.

avatar image
0

Answer by ButtersGoog · May 31, 2016 at 07:08 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Export/Save procedural GameObjects with meshes 4 Answers

How to assign variables like Texture2D, TextAsset, Transform, etc. using code? 1 Answer

Get path of editor script? 2 Answers

Resources.FindObjectsOfTypeAll() doesn't return all Textures 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges