• 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
1
Question by shongololo · Jul 15, 2015 at 11:41 AM · meshcoroutineassetdatabase

Is it possible to speed up insertion of assets into AssetDatabase?

I am generating a lot of procedural meshes (many thousands) which I am then saving to the AssetDatabase. The process of creating the mesh asset in the AssetDatabase seems to be fairly slow.

To deal with the performance penalty, I am limiting the addition of new assets to once a frame (using a coroutine), however, this still slows the framerate to below 15 p/s. As the meshes are generated, they are added to a queue, which the coroutine then dequeues and saves to the AssetDatabase.

Is there a way to speed this process up? Or is there another manner to use the AssetDatabase that is more performant?

Here is the code:

 public class Cache_Manager : MonoBehaviour
 {
     public static Queue <q_struct> cache_build_q = new Queue<q_struct> ();
 
     public IEnumerator cache_coroutine ()
     {
         Debug.Log ("...starting cache builder coroutine");
         while (true) {
             if (cache_build_q.Count > 0) {
                 q_struct item = cache_build_q.Dequeue ();
                 AssetDatabase.CreateAsset (item.mesh, "Assets/UnityLondon3D/cache/" + item.id.ToString () + ".asset");
             }
             yield return 0;
         }
     }
 
     IEnumerator Start ()
     {
         yield return StartCoroutine (cache_coroutine ());
     }
 
     public struct q_struct
     {
         public string id;
         public Mesh mesh;
         
         public q_struct (string _id, Mesh _mesh)
         {
             id = _id;
             mesh = _mesh;
         }
     } 

Comment
Add comment · Show 2
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 _dns_ · Jul 15, 2015 at 02:58 PM 0
Share

Hi, have you tried using AssetDatabase.StartAssetEditing + stop ? I'm not sure of exactly what it does as the documentation + google search is quite sparse on the subject.

Another option would be to create the asset yourself as a yaml text file and let unity discover them and create the corresponding .meta... Well, there is quite a high development cost to just try that...

avatar image shongololo · Jul 16, 2015 at 11:15 AM 0
Share

StartAssetEditing / StopAssetEditing does speed it up a fair bit, it shows a progress bar whilst doing the multiple inserts. So lets you do, say, batches of 100 at a time if one doesn't $$anonymous$$d the progress bar popping up in the foreground.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SgtOkiDoki · Nov 04, 2018 at 12:08 AM

Hey, I found a solution to this

I had +3000 objects to save, and I realized 'AssetDatabase.CreateAsset' is Pretty Slow, so I did like this.

 AssetDatabase.StartAssetEditing();
 foreach(.....)
          AssetDatabase.CreateAsset(....)
 AssetDatabase.StopAssetEditing();

That actually saved me!

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 jaybbo · Nov 09, 2018 at 09:04 PM 0
Share

Then, that foreach loop contains more than 3000 objects, right?

avatar image SgtOkiDoki jaybbo · Nov 10, 2018 at 01:30 AM 0
Share

yes.

If you don't call 'AssetDatabase.StartAssetEditing();' before creating that 3000 objects that take A LOT, but if you actually call it before, it speeds up really a lot.

I believe that's the reason =>

Each Time when you create an asset, 1) unity creates the file on disk,2) imports to project (create temp files), 3) Save all assets etc.

When you call, 'AssetDatabase.StartAssetEditing();' it doesn't import/save(don't know just guessing) immediately, ins$$anonymous$$d you do your process, once you have done, you call 'AssetDatabase.StopAssetEditing();' and then imports all of them at once, and save assets for only 1 time.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

24 People are following this question.

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

Related Questions

Why The shareMesh isn't full load when i load a prefab with SkinnedMeshRenderer in unity? 1 Answer

Trying to make my own plane using only 2 triangles? 1 Answer

Animator.Rebind() not working as expected after manually changing GameObject hierarchy 0 Answers

Creating a Mesh asset inside the editor 1 Answer

Set mesh asset read/write property 0 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