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
0
Question by tomekkie2 · Jan 17, 2012 at 06:54 AM ·

Mesh.CombineMeshes error?

Please, help me to find out why on the following example script from the manual

using UnityEngine; using System.Collections;

 [RequireComponent(typeof(MeshFilter))]
 [RequireComponent(typeof(MeshRenderer))]
 public class example : MonoBehaviour {
 void Start() {
 Component[] meshFilters = GetComponentsInChildren<MeshFilter>();
 CombineInstance[] combine = new CombineInstance[meshFilters.length];
 i = 0;
 while (i < meshFilters.length) {
 combine[i].mesh = meshFilters[i].sharedMesh;
 combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
 meshFilters[i].gameObject.active = false;
 i++;
 }
 transform.GetComponent<MeshFilter>().mesh = new Mesh();
 transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
 transform.gameObject.active = true;
 }
 }

I am getting the error: Assets/example.cs(9,61): error CS1061: Type UnityEngine.Component[]' does not contain a definition for length' and no extension method length' of type UnityEngine.Component[]' could be found (are you missing a using directive or an assembly reference?)

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 syclamoth · Jan 17, 2012 at 07:06 AM

Simple- there's no such thing as a '.length' member on arrays- the correct spelling is '.Length' with a capital L!

You should also look out for this line:

Component[] meshFilters = GetComponentsInChildren<MeshFilter>();

If the line is declared like that, there is nothing telling the compiler that the Components in that array will always be specifically MeshFilter-type components. Instead you should use the line:

MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();

This makes sure that the objects in the array can only be either MeshFilters or objects which derive from MeshFilter.

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 tomekkie2 · Jan 17, 2012 at 07:36 AM 0
Share

Thanks. Now I have to fight back another error: "Assets/example.cs(12,34): error CS1061: Type UnityEngine.Component' does not contain a definition for shared$$anonymous$$esh' " I didn't expect the errors like that because I have just copied and pasted!

avatar image syclamoth · Jan 17, 2012 at 07:58 AM 1
Share

I think, if you just copy and paste, you should definitely expect errors. Copy-pasting code without understanding what it does is a sure path to failure!

In this case, it is because of your variable declaration-

 Component[] meshFilters = GetComponentsInChildren<$$anonymous$$eshFilter>();

It should be more specific:

 $$anonymous$$eshFilter[] meshFilters = GetComponentsInChildren<$$anonymous$$eshFilter>();

That way, the program will know exactly what kind of Component it should be using!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Combine custom AI navigation meshes on game load? 0 Answers

Combine the meshes of primitives so that they share the same material instance? 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