• 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 Fabkins · Jan 11, 2014 at 07:41 PM · uvtile

Advice on optimising a tiling system

Need some advice on generating a large tiled surface. I’ve tried two different approaches and both seem flawed for different reasons.

My first approach was to use Plane object and just instantiate a new one for every title. Setting the texture of the tile was pretty straight forward as it was just a matter of setting the texture.

Problem I found was even on a moderate size board 100x100 , it took an age to instantiate the 1000 tiles (an age being 3 secs on a workstation).

So I then thought I would try dynamically creating a mesh. This was much quicker generating the surface but setting the texture of a tile was a bit of nightmare. Although I got setting the tile texture working, it seems like a really slow operation as I need to update the whole UV map (making a copy of the existing map, modifying the copy, replacing the existing with the copy).

Dynamically changing single tiles is a very heavyweight operation.

So would like some advice on whether there is a way of modifying some UV nodes without having to update the whole UV map for the mesh. Below is the code I use for modifying the uv of my mesh.

 // Set the tile to be one 0-15 (offset) at position x,y on the grid
 function setUVoffset(iX:int, iY:int, iOffset:int)
 {
 var squareNo=(iX+iY*iMapSize)*4; // Get the position of the UV corresponding to a tile
 var fMult: float= 1 / 16f; // There are 16 tiles to choose from
 
 // Get a copy of the existing UV map
 var uv: Vector2[] = new Vector2[iMapSize*iMapSize*4];
 var mf: MeshFilter = GetComponent(MeshFilter);
 uv = GetComponent(MeshFilter).mesh.uv;
 
 // Modify the UV map for just the tile that has changed
 uv[squareNo+0] = new Vector2(iOffset * fMult, 0);
 uv[squareNo+1] = new Vector2((iOffset+1) * fMult, 0);
 uv[squareNo+2] = new Vector2(iOffset * fMult, 1);
 uv[squareNo+3] = new Vector2((iOffset+1) * fMult, 1);
 
 // Replace the UV map of the mesh with the modified one
 GetComponent(MeshFilter).mesh.uv=uv;
 }

Secondly, I am open to any suggestions to a better approach to the tiling. I would still like to know however whether its possible to modify individual UV of a mesh without having to refresh all.

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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Reimporting during play changes UVs/Tiling? 0 Answers

Modify texture coordenates with a shader. 0 Answers

Assigning UV Map to model at runtime 0 Answers

Call a component with different parameters? 2 Answers

How to texture walls in procedurally generated 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