Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by APProjects · Mar 19, 2012 at 08:37 PM · errormeshassetassetdatabase

Save procedural mesh in the editor as asset.

Hi!

I'm curious, how to save a procedural (script generated) mesh as an asset. I was trying to do it, I failed.

What I tried is: get the Mesh Filter component's mesh, store it in a variable and use AssetDatabase.CreateAsset.

I wanted to do it with a custom GUI. There is a button and a textfield. I can name the asset with it. It puts the mesh to Assets/CustomModels/. It makes the asset based on the first selection (Selection.transforms[0]).

When I press the Save Mesh button (I called as that), it makes the asset first time, but after that, it doesn't work.

I guess it can't overwrite the asset, but it even don't work if I give it a new name.

Here is the error I get always:

Couldn't create asset file because the Mesh 'NewPlain' is already an asset at 'Assets/CustomModels/NewPlain.asset'! UnityEditor.AssetDatabase:CreateAsset(Object, String) SaveMeshAsset:OnGUI() (at Assets/Editor/SaveMeshAsset.js:28) UnityEditor.DockArea:OnGUI()

UnityException: Creating asset at path Assets/CustomModels/NewPlain2.asset failed. SaveMeshAsset.OnGUI () (at Assets/Editor/SaveMeshAsset.js:28) System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)

I'm a very beginner script writer, and I don't get the reason of the error. The script first changes the nameOfMesh variable that is modifiable from the GUI.TextField, and after it had to save.

Comment
Add comment · Show 1
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 insominx · Feb 08, 2013 at 10:13 PM 0
Share

There are several places you could get things wrong. $$anonymous$$aybe this video will help: Unity Tips and Tricks

2 Replies

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

Answer by MediaGiant · Jul 23, 2014 at 06:15 AM

The docs say "If an asset already exists at path it will be deleted prior to creating a new asset." which seems to be true if the asset isn't currently selected, otherwise you get the error above. I also tried using the AssetDatabase.DeleteAsset before saving but this broke the reference to the mesh in the original object.

What appears to work is to create an new instance of the mesh you want to save:

 Mesh tempMesh = (Mesh)UnityEngine.Object.Instantiate(originalMesh);
Comment
Add comment · Show 2 · 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 drudiverse · Oct 22, 2014 at 03:55 PM 0
Share

That's a genius answer and is indeed a solution to the issue... in js

var copy : $$anonymous$$esh = Instantiate(original);

didnt even know i could instantiate without position and rotation variables, very convenient.

in memory critical programs i think the copies would have to be cleared afterwards.

avatar image ikv007s · Nov 02, 2018 at 10:35 AM 1
Share

$$anonymous$$y goodness Thanks man i hope you get a kiss from Amber heard. Thanks for the great answer.

avatar image
1

Answer by DaveA · Mar 19, 2012 at 09:09 PM

Try using AssetDatabase.RenameAsset or DeleteAsset before (re)saving, to get rid of any original and references to it.

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 APProjects · Mar 20, 2012 at 12:03 PM 0
Share

"Try using AssetDatabase.RenameAsset or DeleteAsset before (re)saving, to get rid of any original and references to it."

Well, I tried to do that. Even I'm not sure how it works. One thing confuses me.

What I did is: Put the DeleteAsset before the SaveAsset. It was logical for me too. But I got the error even if I did delete and save with an other name. Basicly in the error there was always the first successfully saved asset's name.

It could save only once per game object.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Script to load a text file gives error. 1 Answer

Assigning meshes & materials from Assets, how? 1 Answer

Unity Keeps Giving Me Errors On My Scripts 1 Answer

AssetDatabase.AddObjectToAsset is not persistent? 0 Answers

AddComponent can't find script name MouseOrbit? 1 Answer


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