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 mattgoldman1981 · Oct 02, 2017 at 11:39 AM · collisionvector3mesh.uv

Mesh.uv array index out of range

I've been following along on this tutorial on making a VR fruit ninja game. So far, mostly so good (I have another question posted about an unrelated, and non-showstopper issue).

My problem is that using the fruit object assets provided by the author, everything works fine. And using primitive objects created in Unity (i.e. a cube), everything works fine. But when I import my own objects, I get this error:

 IndexOutOfRangeException: Array index is out of range.
 BLINDED_AM_ME.MeshCut.Cut (UnityEngine.GameObject victim, Vector3 anchorPoint, Vector3 normalDirection, UnityEngine.Material capMaterial) (at Assets/BLINDED_AM_ME package/Scripts/MeshCut.cs:111)
 SwordCutter.OnCollisionEnter (UnityEngine.Collision collision) (at Assets/SwordCutter.cs:17)

This is the line that seems to be causing the problem:

 new Vector2[]{ _victim_mesh.uv[p1],       _victim_mesh.uv[p2],       _victim_mesh.uv[p3] },

I'm creating my objects in Blender, and upon some investigation I've found that the UV map from external programs can cause unexpected results. However, there is no UV map applied to these objects in Blender.

I've also read that the array size needs to be two, however the start of this loop looks like this

 for(int i=0; i<indices.Length; i+=3){
 
                     p1 = indices[i];
                     p2 = indices[i+1];
                     p3 = indices[i+2];

So to me it looks like this error should also be thrown, but for some reason I don't get the issue if I sue objects created in Unity (like a cube) or use the assets provided by the tutorial.

I'm a total noob at this, can someone give me a bit of direction?

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 hexagonius · Oct 02, 2017 at 10:57 PM 0
Share

You should know how many UVs your models have and adopt the code to that, maybe just check the length of the uvs array too and break when inappropriate.

1 Reply

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

Answer by Bunny83 · Oct 03, 2017 at 02:02 AM

Your model simply doesn't have any UV coordinates. You probably didn't unwrap your object in blender. Maybe also have a look at this page

When you inspect a Mesh in the inspector it tells you what vertex attributes the mesh has. Here's an image of the default cube mesh:

alt text

The "red" is the number of vertices.
The "green" the number of triangles.
The "yellow" tells you that the mesh has a UV channel
The "orange" tells you that the mesh has a second UV channel.

If your mesh doesn't have the "uv", the mesh simply doesn't have uv coordinates. That's why the array is empty.

ps: Never do something like this:

 new Vector2[]{ _victim_mesh.uv[p1],       _victim_mesh.uv[p2],       _victim_mesh.uv[p3] },

Using _victim_mesh.uv will create a new array each time you access it. If you work with any mesh attributes you should always cache the arrays in local variables:

 Vector2[] uv = _victim_mesh.uv;
 
 new Vector2[]{ uv[p1], uv[p2], uv[p3] },

Of course this only works when your mesh actually has uv coordinates.


meshattributes.png (7.0 kB)
Comment
Add comment · Show 1 · 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 mattgoldman1981 · Oct 03, 2017 at 10:03 AM 0
Share

Thanks for the clear explanation. I didn't realize there were these layers of complexity! $$anonymous$$uch appreciated, and for the additional tip too (although that's not my code, its from the BLINDED_A$$anonymous$$_$$anonymous$$E asset pack).

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

124 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Applying custom forces without rigidbody collisions? 0 Answers

Why does this script check for raycast collision? Is it necessary? 1 Answer

Issues with Bullet Ricochet 1 Answer

Wht isn't the sphere moving and rebounding properly? 1 Answer

Respawn when a character hits an object with a tag of "Kill" , but after 3 deaths the controller is destroyed 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