Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 YCB · Oct 30, 2019 at 01:53 AM · .fbx

how to get .fbx vertex count when unity import it

  void OnPreprocessModel()
         {
             ModelImporter modelImporter = assetImporter as ModelImporter;
             modelImporter.importMaterials = false;
         }
         void OnPostprocessModel(GameObject g)
         {
             GameObject go =GameObject.Instantiate(g);
             MeshFilter meshFilter;
             foreach (Transform child in g.transform)
             {
                 meshFilter = child.GetComponent<MeshFilter>();
                 if (meshFilter!=null)
                 {
                     Debug.LogError(meshFilter.mesh.vertexCount);
                     //i want to get it !!!!
                 }
             }
         }

I try to get it , but unluckly no use. because when it create successed, the Skinned Mesh Render-- Mesh property is Missing(Mesh)

please help! please help! please help!

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
0

Answer by Bunny83 · Oct 30, 2019 at 03:06 AM

Well there are a few things you should keep in mind:

  • First of all an imported model might have either a MeshRenderer + MeshFilter component or a SkinnedMeshRenderer. So you may want to check for both a SkinnedMeshRenderer and a MeshFilter in case no SkinnedMeshRenderer was found.

  • The second point is: do not use the mesh property inside the editor, ever. The mesh property will try to instantiate the mesh for this MeshFilter only. However this only works at runtime and is only ment for runtime use. Inside the editor you should always use the sharedMesh property.

  • inside editor code you should not use Instantiate unless you really know what that means. Instantiating an object means you create a clone in the current scene. Note that this clone is not connected to the prefab / source object it came from. For anything prefab related inside the editor you want to have a look at the PrefabUtility class and in particular the InstantiatePrefab method.

To count all the vertices of a prefab when it's imported you may want to use:

 void OnPostprocessModel(GameObject g)
 {
     int vertexCount = 0;
     foreach (var smr = g.GetComponentsInChildren<SkinnedMeshRenderer>())
         vertexCount += smr.sharedMesh.vertexCount;
     foreach (var mf = g.GetComponentsInChildren<MeshFilter>())
         vertexCount += mf.sharedMesh.vertexCount;
     Debug.Log("Imported model "+g.name+" has " + vertexCount + " vertices", g);
 }

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

115 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 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 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 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 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

blender cannot convert .blend file to FBX? 6 Answers

How can I convert .anim files to .fbx files? 1 Answer

maya model UV object disappear 0 Answers

Adding Blender Animations to an Already Imported Model 1 Answer

I want to have a Unity Scene which is Pitch Black. [Read Below] 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