- Home /
RaycastHit.textureCoord is broken?
Can anyone please confirm if RaycastHit.textureCoord is actually working? No matter what I do it always returns 0,0. I have a Convex MeshCollider on a UV'd cube mesh.
I even recreated the basic example from the docs RaycastHit-textureCoord and that doesn't work either.
Via debugging, I have determined that the raycast is hitting the correct object, and returns the correct texture name.
Answer by Bunny83 · Jan 02, 2017 at 09:48 PM
It does work, but not with a convex mesh collider. It only works with a normal mesh collider. If you check "convex", Unity will create a new mesh which will be the convex hull of the original mesh. Therefore the meshcollider has no logical relation to the original mesh and doesn't have texture cordinates at all. The convex mesh usually looks different from the original mesh.
You only need a convex collider if the object is used as rigidbody. If you need both, you can add two colliders, one convex and a normal one. Place them on different layers to control the behaviour / interaction.
I'm not sure i understand what a shader has to do with all that. A collider is a pure logical object that has no relation to rendering. So a collider always works the same, no matter if the object is actually visible.
Reading or writing pixels to a texture requires the texture to be marked as read- / writeable. Textures that are created at runtime are automatically read/writeable.
If you experience problems with changing textures and not seeing any result in the scene might be related to (static) batching. Do not mark an object as static if you change anything on that object. If an object is batched the original renderer becomes useless as the object is now part of a big (batched) mesh.
Thank you for the detailed reply.
I figured it out a couple of hours ago, but my answer was awaiting moderation, and now it's disappeared. :S
The issue was indeed due to the Convex option. though I thought that the Generate Colliders option needed to be ticked on model import also, but I guess not.
You deserve the answer. I can't yet though. my own answer must still be locked in limbo & I'm unable to award you it, but I will when chance comes.
Edit: There we go. Thanks again! :)
Answer by Kiefy · Jan 04, 2017 at 08:47 AM
Ok, I figured it out.
When importing the mesh, you must tick
Generate Colliders to add the Mesh Collider, instead of adding one yourself. and
make sure Convex is unticked on the Mesh Collider component.
Your answer
![](https://koobas.hobune.stream/wayback/20220612103847im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
RaycastHit.textureCoord not working on my non-Convex collider. 2 Answers
Sphercast hitinfo TextureCoord rounded? 1 Answer
Why in Unity3D RaycastHit. textureCoord always return 0,0 after building the project? 1 Answer
RaycastHit Texturecoord doesn't work with separate colliders 0 Answers
RaycastHit.textureCoord ranges from (0,0) to (1,1) for each face. 2 Answers