Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 newlife · Dec 09, 2019 at 11:29 PM · raycastgraphicsmesh collidermesh verticesuv coordinates

RaycastHit.textureCoord returns zero on Android if mesh is not set to readable

Hello, we are using RaycastHit.textureCoord to find the UV coordinates of a car mesh collider in order to apply a decal on the car body.

The mesh of the mesh collider is non convex and is taken directly from the car model. Everything works correctly in the editor, but its not in Android build.

Specifically, RaycastHit.textureCoord always returns zero in the Android build unless the mesh of the mesh collider is set to readable.

Is there any way to avoid this? Enabling Read / write means to double memory occupation.

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 Bunny83 · Dec 10, 2019 at 11:33 AM

So you want to read mesh information without having the mesh data actually available in memory? How do you think this should work? If you just upload the mesh data to the GPU memory you can not do any raycasting against the collider and query mesh relevant data (like the UV coordinates). If you need to query texture coordinates from the mesh it has to be readable. There's no way around that.


How large is your mesh that you worry about having it in RAM? Mesh data, even for moderate complex meshes, shouldn't be an issue compared to texture or audio data.

Comment
Add comment · Show 3 · 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 newlife · Dec 10, 2019 at 11:42 AM 1
Share

This is something that its not mentioned on RaycastHit.textureCoord documentation. It only says "Note: A textureCoord requires the collider to be a $$anonymous$$eshCollider".

For what concern enabling read write checkbox, even Unity documentation pushes to avoid this whenever is possible, even by specifying when it should be enabled https://docs.unity3d.com/ScriptReference/$$anonymous$$esh-isReadable.html

In most cases, you should disable this option to save runtime memory usage. You should only enable it under the following circumstances:

  • When you read from or write to the $$anonymous$$esh data in your code.

  • When you pass the $$anonymous$$esh to StaticBatchingUtility.Combine() to combine the $$anonymous$$esh at run time. -When you pass the mesh to CanvasRenderer.Set$$anonymous$$esh.

  • When you use the $$anonymous$$esh to bake a Nav$$anonymous$$esh using the Nav$$anonymous$$esh building components at run time.

  • When the $$anonymous$$esh is convex, you use the $$anonymous$$esh with a $$anonymous$$esh Collider, and the $$anonymous$$esh Collider's Transform has negative scaling (for example, (–1, 1, 1)).

  • When you use the $$anonymous$$esh with a $$anonymous$$esh Collider, and the $$anonymous$$esh Collider's transform is skewed or sheared (for example, when a rotated Transform has a scaled parent Transform).

  • When you use the $$anonymous$$esh with a $$anonymous$$esh Collider, and the $$anonymous$$esh Collider's Cooking Options flags are set to any value other than the default. -When using a $$anonymous$$esh with a Particle System's Shape module or Renderer module when using not using GPU instancing. Note that the Particle System will automatically change $$anonymous$$eshes to readable when assigned through the inspector

avatar image s4shrish newlife · Apr 24, 2020 at 02:32 PM 0
Share

Damn right. Thank you.

It was very weird how the textureCoord was returning value in the editor and wouldn't in the build. $$anonymous$$y mesh is just a well rounded sphere, and game isn't very demanding, so now it works. But this needs to be addressed in TextureCoords' documentation.

Edit: It is there, but ONLY in the EXA$$anonymous$$PLE's comments. That is a horrible way of giving such a crucial information. The example is not there for giving such info. It is there for giving an EXA$$anonymous$$PL$$anonymous$$

avatar image newlife · Dec 11, 2019 at 01:45 AM 0
Share

There is a sort of workaround to this, at least for our use case. We need to access the UV coordinates only in the menu scene, so we use

 car$$anonymous$$esh = carBody.gameObject.GetComponent<$$anonymous$$eshFilter>().shared$$anonymous$$esh;
 car$$anonymous$$esh.Upload$$anonymous$$eshData(true);

to free memory before loading the race scene, where we don't need anymore to access mesh data. Can anyone expert can confirm that this is correct?

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

180 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

Related Questions

Adding a AO/Lightmap at runtime using second UV channel on tiled textures/materials 0 Answers

Mesh Colliders as triggers not working... Work-arounds (raycast)? 4 Answers

Is it possible to access other objects in a shader function? 0 Answers

3d ground for 2d gameplay / side scroller 1 Answer

Circular Mesh UV interpolation for tileable texture 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