- Home /
Can't include shaders in packages exported by ExportPackage. How to work around this?
I am having trouble with this line in my code:
AssetDatabase.ExportPackage(AssetDatabase.GetAssetPath(items[0]),
"C:\\path\\" + items[0].name + ".unitypackage",
ExportPackageOptions.IncludeDependencies);
Here, items is a List<object>
and each item is guaranteed to be an asset in the database. However, in any case where a non-default shader is listed as the item to export, or the item includes a non-default shader as a dependency (such as a material that uses it), I get this error message:
If I change the code to this:
AssetDatabase.ExportPackage(AssetDatabase.GetAssetPath(items[0]),
"C:\\path\\" + items[0].name + ".unitypackage",
ExportPackageOptions.Default);
I.e. instead of the IncludeDependencies options I use Default, I still get the error. My unity version is 4.3.4f1 and my Environment is Window 7 (Japanese). The odd thing is, if I do the export manually, through the menu Assets->Export Package, it works fine.
Answer by PokeJoe · Mar 03, 2015 at 10:50 AM
In case any one comes along with this problem in the future, I figured it out.
In the second parameter, I use items[0].name
. In the case of most objects, this is fine because it contains the name of the object excluding any subdirectories it's in. However, in the case of shaders, it contains the display name of the shader, as you select it from the list when making a material. This is NOT the same as the name of the asset in the project.
For example, I made a shader called VarBrush.shader, which is listed in the menus as Outlined/VarBrush. The problem is, its .name property is "Outlined/VarBrush". When exporting, Unity chokes on trying to put a slash in the filename (it won't create nonexsting directories from a specified file path). This is why the error is in copying it from Unity's temporary packaging directory into my specified filename.
My solution:
string namesan = items[0].name.Replace('\\', '_').Replace('/','_');
//Sanitize slashes in name
AssetDatabase.ExportPackage(AssetDatabase.GetAssetPath(items[0]),
"C:\\path\\" + namesan + ".unitypackage",
ExportPackageOptions.IncludeDependencies);
Your answer
![](https://koobas.hobune.stream/wayback/20220613184258im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Export list of prefab to asset bundles recursively 0 Answers
How do you make an X-ray vision following the mouse? 1 Answer
Show camera view in an editor window 1 Answer