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
1
Question by Spidyy · Jul 25, 2013 at 04:07 PM · meshsavescriptableobjectproceduralfile

How should I save the Meshes generated inside a ScriptableObject

I have a ScriptableObject, saved as a .asset, and I want it to contains an array of generated meshes.

 public class myObject : ScriptableObject
 {
     [SerializeField]
     private Mesh[] myMeshes;
     
     void Construct(int count)
     {
         myMeshes = new Mesh[count];
         
         for(int i = 0; i < count; i++)
         {
             myMeshes[i] = new Mesh();
             
             // Filling the mesh with vertices and triangles
         }
     }
 }

I want my meshes to be saved, but I will have hundreds of .asset, and if I save them externally, I will have tens thousand meshes and as much files.

Is there a way to save the meshes inside my ScriptableObject's .asset file, so they are saved/loaded properly when opening/closing Unity?

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 Jake-L · Jul 26, 2013 at 08:57 AM 0
Share

Shouldn't this work right out of the box? Did you tried to make the array public? Though [SerializeField] should have the same effect...

avatar image Spidyy · Jul 26, 2013 at 01:21 PM 0
Share

Well this don't seems to work. When trying to reach the meshes, all I got is an array of null references.

1 Reply

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

Answer by Bunny83 · Jul 26, 2013 at 01:27 PM

Meshes are assets like Textures or GameObjects. They need to be saved seperately as asset to the project or they will be lost once you change the gamemode.

Keep in mind that a ScriptableObject also has the OnEnable callback, so you could reconstruct your meshes at runtime. If you want to create them at edit time, you have to save them as assets with AssetDatabase.

edit

Just read your concern about having hundreds of asset files. You can add assets to a single asset file with AssetDatabase.AddObjectToAsset. Pretty much the same way Unity handles the importing of an fbx file. It adds the imported mesh as subasset to the actual fbx asset. The fbx asset isn't even included in the build, only the subassets that are referenced somewhere.

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 Bunny83 · Jul 26, 2013 at 01:36 PM 0
Share

$$anonymous$$eep in $$anonymous$$d that $$anonymous$$esh also has a name property which you should set to a meaningful name before adding it to your asset.

avatar image Spidyy · Jul 26, 2013 at 03:03 PM 0
Share

It works, well I saved them in separate files than myObject's one, because the assets become all shuffles in the same file and I have to search myObject amongs maaany meshes. But it works. Thanks. :)

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

17 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

Related Questions

How do I properly save a procedurally created mesh? 1 Answer

Best way to save procedural world/mesh? 0 Answers

Creating asset bundles realtime 0 Answers

Adding extra materials to a mesh programmatically 0 Answers

UV Mapping a Sphere at runtime 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