Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 haqan · Oct 16, 2020 at 01:50 PM · texturemeshpaintuv coordinatesuvmapping

How to get uvCordinat of raycast hit without mesh collider

Hi i want to paint texture of hitted enemy and i have everything except one thing. i can't get texture uvcoordinat of object because i am using box colliders on enemy (legs , arms , head ...) so how can i get texcoordinate in this situation

Current stuck : when i hit collider im calculating the nearest mesh vertex to hit.point but still can't get hitted point uvcordinat

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
0

Answer by FM-Productions · Mar 31 at 05:14 PM

You can't really do that because a sphere collider representation doesn't have uvs, it's just a mathematical concept without underlying mesh.

If you want to get your exact uv coordinates If you have a SkinnedMesh, you probably need to bake it into a new Mesh and use that, but I'm sure that there are libraries for that somewhere. An example for a use case I had: I wanted to figure out the UVs of the visual sphere mesh that is on the sphere object (basically the mesh of the MeshFilter.sharedMesh of that object). What I did for this is to set up a MeshCollider as child of the sphere collider, then assign the same Sphere Mesh to it as the one the MeshFilter of a Sphere object uses. It is important to set the mesh collider to non-convex (cooking option settings might not be required, but I disabled them) so that the visual mesh representation and the physical mesh representation is the same. Then I disabled that collider and stored a reference to it on a script on the original sphere parent object. So when I hit the sphere, I check for that component, then get the MeshCollider from it and perform the same raycast, but only against this one collider, using Collider.Raycast (on the collider instance) instead of Physics.Raycast. Then I got the uv coordinates I was looking for. While testing, apparently collider.Raycast only gets me valid values when the collider is enabled, and the object it sits on is active. Since I don't want that collider to be part of my regular physics interactions, I only activate and enabled it just before I do the raycast, and then I disable it again. Some people in other threads mention that sometimes it doesn't work in builds. The reason is because some meshes might have isReadable not enabled, that means that after the mesh gets uploaded to the GPU-accessible memory, it gets cleared from the CPU-accessible memory - a sideeffect seems to be that the RaycastHit texture coordinates can't retrieve valid values when this is the case. The solution is to set the "readable/writeable" flag on the import settings of the model/fbx that stores your mesh to true (mesh needs to have isReadable enabled)

If you don't want to do that, you might have to create a compute shader and iterate all vertices of your (baked) visual mesh and store the vertexID that is the closest to your hit point, and then use the uv coordinate on that vertexID (index) as your value.

Comment
Add comment · 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

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

185 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 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

UV V coordinate Not showing on Texture. 1 Answer

Apply a texture on model 3D with the Mouse Position taking account of the scale/position/rotation of uv // Appliquer une texture sur un modele 3D en fonction de la position du curseur en prenant en compte la rotation/taille/position des uv 0 Answers

Painting on objects at runtime/in editor 1 Answer

Change texture of individual triangle on a mesh? 3 Answers

How to texture an irregular (hexagon) shape (mesh) ? 1 Answer


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