Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 mdowd · Aug 31, 2016 at 08:00 AM · meshrenderinguvsuvmapping

Changing mesh.uv works in editor, but not on Android

Hello,

I'm working on a project where I am trying to programmatically adjust the UVs of meshes in my scene.

The meshes I'm working with represent the floors of the level and the changes to the UVs are to make sure the floor textures are consistently tiled regardless of the floor mesh size.

The changes to the UVs seem to work fine when running the game in the Unity Editor, but when I export a build to an Android device the changes don't seem to take effect.

The code below is called on Awake()

 foreach (var floor in area.FloorSurfaces) {
 
                 MeshFilter meshFilter = floor.GetComponent<MeshFilter> ();
 
                 List<Vector2> uvs = new List<Vector2> ();
                 foreach (var vertex in meshFilter.mesh.vertices) {
 
                     if (floor.transform.up.y > .5f) {
                         uvs.Add (new Vector2 (vertex.x * (floor.transform.lossyScale.x), vertex.z * (floor.transform.lossyScale.z)));
                     } else {
                         uvs.Add (new Vector2 (vertex.x * (floor.transform.lossyScale.x), vertex.y * (floor.transform.lossyScale.y)));
                     }
                 }
 
                 meshFilter.mesh.uv = uvs.ToArray();
             }

alt text alt text

android.png (218.3 kB)
unity-editor.png (117.2 kB)
Comment
Add comment · Show 2
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 mdowd · Aug 31, 2016 at 07:16 AM 0
Share

I just found that if I make the floor not "static" then everything works fine. I might try to handle this in an AssetPostProcessor ins$$anonymous$$d.

avatar image mdowd · Aug 31, 2016 at 07:37 AM 0
Share

Doing this in a AssetPostProcessor during OnPostprocess$$anonymous$$odel allowed this to work and keep the mesh static :-)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mdowd · Sep 01, 2016 at 08:31 AM

The problem wasn't specific to Android, it was in any build. I had the mesh marked as static and trying to edit the uvs after the game started was throwing errors.

The solution I ended up going with was to create a AssetPostProcessor and handle this in the OnPostprocessModel event, which makes much more sense for what I was trying to do anyway.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Problem when creating UVs coordinates 1 Answer

UV V coordinate Not showing on Texture. 1 Answer

Creating a mesh programatically for a tile-based 2D game 1 Answer

Is it possible to render a mesh from code? 2 Answers

Close meshes render in 2D, but not 3D 0 Answers


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