Search Unity

Can I suppress warnings when I use RaycastHit.textureCoord2?

Discussion in 'Physics' started by Snubber, Jun 21, 2022.

  1. Snubber

    Snubber

    Joined:
    Jan 20, 2020
    Posts:
    65
    Hello! I am using textureCoord2 to store data in my meshes about what type of material the player is running on to play different footsteps sounds. However not all of my meshes have this data. So when I check for it and the textureCoord2 data isn't there I get this warning:
    Code (CSharp):
    1. Mesh "chonx mesh" does not have a 2nd Texture coordinate channel.
    2. Defaulting to channel 1
    3. UnityEngine.RaycastHit:get_textureCoord2 ()
    But there doesn't seem to be a way to check if the data is there or not. Is there at least a way to suppress this warning? (it's happening every frame)
     
    hypnoslave and recyclingriot like this.
  2. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    439
    Found this post after banging my head against the wall for a bit. Here's the solution, in case someone else finds this:

    Code (CSharp):
    1. Vector2 lightmapUV;
    2. MeshFilter m = hit.collider.gameObject.GetComponent<MeshFilter>();
    3. int lightmapIndex = hitRenderer.lightmapIndex;
    4. if(lightmapIndex == 1)
    5. {
    6.     Vector4 lightmapData = hitRenderer.lightmapScaleOffset;
    7.     Vector2 uv = hit.textureCoord;
    8.     // Convert hit textureCoord2 to lightmap space
    9.     lightmapUV = new Vector2(uv.x * lightmapData.x + lightmapData.z, uv.y * lightmapData.y + lightmapData.w);
    10. }
    11. else
    12.     lightmapUV = hit.lightmapCoord;
     
    Last edited: Mar 27, 2024