Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 idris_ · Jul 09, 2015 at 07:51 PM · instantiatememory managementtrailcombinemeshes

Is there a maximum amount of memory Unity assigns for instantiating meshes?

I'm working on a project where I am importing some mocap data of people doing some actions into Unity, the idea is to play through the data with each point leaving a trail as it moves.

[EDIT] This is to be used with the Oculus rift, so I'm using the Oculus OVRcamera prefab

The way I have set it up so far, at start up I read each mocap file(one per frame - 325 frames) and store the position vectors in a huge 2D array, one dimension for frame the other for the points(325 frames by 982 points). Then I create a mesh per frame and this is where my troubles start. I iterate through the frames and instantiate a basic mesh at each point (from the mocap data) for that frame, I then combine those instantiated objects into one mesh and destroy the original instantiations. BUT I can only do this if my frame range in 100, any more and Unity just crashes and closes down.

 void createLayers()
 {
     // iterate through each frame
     for (int i =0; i<m_frameRange; i++) 
     {
         
         // temporary game object to be parent of instantiated meshes, 
         // used for combining meshes
         GameObject _layers = new GameObject();
         
         // array of game objects to hold the combined meshes    
         m_mergedMeshes[i] = new GameObject("Layer_"+i.ToString("D4"));
         
         // iterate through each point
         for(int j=0;j<m_totalPoints;j++)
         {
             GameObject tmp = Instantiate(m_origMesh);
             tmp.transform.position = Vec4ToVec3 (m_pointData [m_startFrame+i,j]);
             tmp.transform.parent = _layers.transform;
         }
         
         combinePoints(_layers,i);
         
         Destroy (_layers);            
     }
     
 }



My combinePoints functions is:

     void combinePoints(GameObject _objects, int index)
     {
         //_object is the parent object of the instantiated objects
         // index is related to which frame this mesh is

         MeshFilter[] meshFilters    = _objects.GetComponentsInChildren<MeshFilter> ();
         Transform[] meshTrans         = _objects.GetComponentsInChildren<Transform> ();
         CombineInstance[] combine     = new CombineInstance[meshFilters.Length];
 
         int id = 0;
         for (int i=0; i<meshFilters.Length; i++) 
         {
             if(meshFilters[i].sharedMesh == null){continue;}
             combine[id].mesh = meshFilters[i].sharedMesh;
             combine[id].transform = meshFilters[i].transform.localToWorldMatrix;
             meshFilters[i].gameObject.SetActive(false);
             id++;
         }
 
         m_mergedMeshes [index].AddComponent<MeshFilter> ();
         m_mergedMeshes [index].GetComponent<MeshFilter>().mesh = new Mesh();
         m_mergedMeshes [index].AddComponent<MeshRenderer> ();

 
         m_mergedMeshes [index].GetComponent<MeshFilter>().mesh.CombineMeshes(combine,true,true);
         m_mergedMeshes [index].SetActive (true);
         m_mergedMeshes [index].GetComponent<Renderer> ().enabled = false;
 
     }


Is this due to me running out of memory or not doing this in an efficient way? Any help would be much appreciated! Also my plan for creating the tails was to turn on or off the meshes depending on the current frame, this way no objects have to be created dynamically which could potentially slow down the FPS. I tried using a particle system to emit meshes but it was way too slow with the number of points I had! Any other ideas of ways to create these trails would be much appreciated also! Thanks in advance

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Dave-Carlile · Jul 09, 2015 at 07:52 PM

There is a maximum of 65534 vertices in a mesh. You can use child objects with separate meshes if you need more.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

2D Wave Methods ? 1 Answer

Checking if object intersects? 1 Answer

Order of object instantiation scripting issues 0 Answers

AI won't move when Instantiated but will if i drag them in? 0 Answers

How can i stop my game from laging during instantiation? C# 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