- Home /
RaycastHit textureCoords return Vector2.zero on iOS only despite proper setup
I'm trying to set up a system where the player can rotate and tap on different potions of a 3D mesh, and I was hoping to use a Splat Map combined with the textureCoord feature in RaycastHit to detect what part of the 3D model was tapped on by what color I get back.
I'm aware that there are limitations to RaycastHit.textureCoord. I already have this setup and working in Editor on PC and Mac, but it fails on iOS. As best as I can tell from device logs, I get back Vector2.zero regardless of where the RaycastHit occurs, despite the fact that the exact same code works precisely as intended in Editor. The code in question is below, and again I do have this setup right. It's using a MeshCollider and it is *not set to convex.
public bool PointHasGrowableMaterial(RaycastHit hit)
{
if (invalidColors.Length == 0) return true;
Vector2 pixelUV = hit.textureCoord;
pixelUV.x *= materialMap.width;
pixelUV.y *= materialMap.height;
Color splatColor = materialMap.GetPixel((int)pixelUV.x, (int)pixelUV.y);
for (int i = 0; i < invalidColors.Length; i++)
{
if (splatColor.Approximately(invalidColors[i], colorTolerance))
return false;
}
return true;
}
Can any tell me if there's a limitation to hit.textureCoord on mobile or iOS specifically? I think the limitation must be related to either the Mesh asset, the MeshCollider or the Raycast API but I can't find any documentation or questions where a similar issue was asked
Ok! For me turning on "Read/Write Enabled" from import settings fixed the issue.
Answer by jnikaes_dualcat · Jul 07, 2021 at 07:26 PM
Hi there, having the same issue. Did you solve it at some point? Non-convex collider as well.
Answer by SlothMachine · Dec 16, 2021 at 09:50 PM
Solution found: Have "Read/Write Enabled" on from import settings.