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 /
This question was closed Nov 13, 2013 at 08:39 PM by Kiloblargh for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Kiloblargh · Nov 13, 2013 at 06:40 PM · nullwarningcombineinstance

Combine mesh instance N is null, (but why?)

I've seen occasional "Combine mesh instance 0 is null" warnings before, but this script is giving tons of them each time it runs.

(......combine mesh instance 1263 is null, combine mesh instance 1266 is null, combine mesh instance 1269 is null, combine mesh instance 1272 is null...)

It's only one every three, for whatever reason.

I don't understand what's wrong here, or how to fix it, and why I'm not getting any NullReferenceException errors if those warnings really mean what they say.

And other than generating over a thousand warnings, the function works just fine- it IS currently combining all the plants into one mesh, and all their shadows into another mesh.

the offending code:

 function Flatten () {
 var meshFilters = GetComponentsInChildren.<MeshFilter>() as MeshFilter[]; //find all meshes
 var shadowMFs : List.<MeshFilter> = new List.<MeshFilter>();
 var solidMFs : List.<MeshFilter> = new List.<MeshFilter>();
 for (var pmf : MeshFilter in meshFilters) //sort all meshes into shadows and not-shadows
     {
     if (pmf.gameObject.layer == 27) { shadowMFs.Add (pmf); }        
     else { solidMFs.Add (pmf); }
     }
 var combineShadows : CombineInstance[] = new CombineInstance [shadowMFs.Count];
 for (var i = 0; i < shadowMFs.Count; i++) //build a CombineInstance for all the shadows
     {
     combineShadows[i].mesh = shadowMFs[i].sharedMesh;
     combineShadows[i].transform = shadowMFs[i].gameObject.transform.localToWorldMatrix;
        shadowMFs[i].gameObject.SetActive (false);
     }
 Debug.Log ("ShadowMFs :" +i); 
 transform.Find("Shadows").GetComponent (MeshFilter).mesh = new Mesh ();
 transform.Find("Shadows").GetComponent (MeshFilter).mesh.CombineMeshes (combineShadows); //combine them
 transform.Find("Shadows").gameObject.SetActive (true);
 var combinePlants : CombineInstance[] = new CombineInstance [solidMFs.Count];
 for (var j = 0; j < solidMFs.Count; j++) // build a CombineInstance for all the solid objects
     {
     combinePlants[j].mesh = solidMFs[j].sharedMesh;
     combinePlants[j].transform = solidMFs[j].gameObject.transform.localToWorldMatrix;
        solidMFs[j].gameObject.SetActive (false);
     }
 Debug.Log ("SolidMFs :" +j); 
 transform.GetComponent (MeshFilter).mesh = new Mesh ();
 transform.GetComponent (MeshFilter).mesh.CombineMeshes (combinePlants); // /!\ THE WARNING IS CAUSED HERE /!\
 transform.gameObject.SetActive (true);
 renderer.sharedMaterial = solidMat;
 for (var childT : Transform in myTransform as Transform) // clean up empty prefabs
     {
     if (childT.gameObject.name == "Shadows") {
         childT.gameObject.GetComponent.<Renderer>().sharedMaterial = shadowMat;
         } else {
         Destroy (childT.gameObject, 0.1);
         } 
     }
 yield;    
 }
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 Kiloblargh · Nov 13, 2013 at 08:42 PM 0
Share

Thanks! But turns out it was the prefabs. Derp. They had some empty mesh filters I didn't know about (and the clover stems had mesh colliders by accident.) Fixing the prefabs got rid of all but two errors, and adding the line

 if (!pmf.mesh) {continue;}

in the first for loop got rid of those too.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Starwalker · Nov 13, 2013 at 07:04 PM

You'll need to put a Debug.Log of the List.Count value before and after each of the type of combine operations, I'm guessing that when you hit the play, the List have no mesh to combine in that particular frame or the mesh's its supposed to combine are not instantiated already, and when you do a list operation on an un-initialized list, the errors will show up.

Again this would be the 1st step I would take to check why nulls happen. The other solution is to put an if() statement before each loop, something like: if(solidMFS) { do list operation } or if(solidMFS.Count >= 0) { do list operation }, this is done so that the loop only executes if the list is initialized and not on a null list. And this is also a solution if the 1st debug test lead to null values for a few frames. If any List operation is done which is List element dependent (on a null valued element), it will break the whole flow if that script.

Hope it helps.

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

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

Warning, null Texture passed to GUI.DrawTexture 0 Answers

Missing Behaviours still process as if they exist? 0 Answers

Array containing destroyed object = Null? 1 Answer

Find if no objects with tag exist 3 Answers

Checking for null elements in a subset? 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