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
1
Question by Flamboozle · Aug 05, 2017 at 10:23 PM · 2dtexturemeshtileuv mapping

How do I use many different tile textures for one mesh? 2D Tile based game.

I am making a 2D sandbox/tile based game (like terraria/starbound), and I am restarting my tile system. I know how to create a world/chunks/tiles for the game using a single mesh per chunk. The mesh contains squares to represent each tile as you could imagine, and I map the UVs for the mesh from a single texture.

But I want to be able to make many different variations for each tile (such as dirt, stone, etc.), and these tiles would consist of fulls blocks, straight-half blocks (4 sides), and diagonal-half blocks (4 sides). And each of these 9 options would have 4+ slight variations to make the game feel more random. So that is 36 versions of a roughly 18x18pixel texture for each tile type.

The method I am using now maps the tile from a SINGLE tile sheet that is the gameobject's material, that would contain all of the tile types, but as I added more tiles the single texture would get bigger and bigger to fit so many variations.

How can I map textures from different PNG files onto my mesh? Sorry if this is confusing, maybe there is a better method or maybe it is complicated. Any ideas would be appreciated.

Here are examples of Starbound's and Terraria's sprite sheet for a single tile.

alt text

alt text

dirt.png (21.8 kB)
Comment
Add comment · Show 3
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 Cherno · Aug 06, 2017 at 12:04 AM 1
Share

Your Tile class needs to have a variable that holds the material/texture, or material/texture name, so your mesh/chunk generating method knowd which material/texture to use.

avatar image Flamboozle Cherno · Aug 06, 2017 at 03:07 AM 0
Share

But how do you link the UV's with the correct material to use. The chunk object just renders using whatever material is on it, but I can't get it to use external materials.

avatar image Cherno Flamboozle · Aug 06, 2017 at 09:30 AM 0
Share

It goes like this. Your tile class deter$$anonymous$$es the material to use. The chunk generating method keeps a list of materials that are being used for the mesh. If it reaches a tile that uses a material not yet in use, the resulting triangles are used with a new submesh. It's hard to explain but I sugggest reading up on using submeshes to use multiple materials with a mesh created from script.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FlaSh-G · Aug 06, 2017 at 12:31 AM

Is there a specific reason you want to use a single mesh other than reducing draw calls? Because that's what batching is doi g for you anyway. Have SpriteRenderers with sprites from the same texture and Unity will batch draw calls for you.

Comment
Add comment · Show 1 · 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 Flamboozle · Aug 06, 2017 at 12:39 AM 0
Share

I made the game work with sprite renders using a pooling system, but the amount of tiles on screen is about 80x45 = 3600 sprites for just the tiles. I was planning on including walls and other game objects on the scene and I found my FPS reaching about 55fps without implementing lighting and nearly any CPU calculations yet. I don't think I was doing it wrong because I first tried SpriteTile's (https://www.assetstore.unity3d.com/en/#!/content/13794) tile pooling, and then I recreated my own with the exact same idea and got similar fps.

I was testing if I could create the same exact system for tiles with much better performance by using $$anonymous$$esh Renders ins$$anonymous$$d of Sprite Renders (and far less of them), and in the process hopefully learn a thing or two about Unity's rendering systems because I am fairly new to it.

Also I've been reading around about creating new textures at run time in code so I'll see if I can get around to my idea using that.

avatar image
0

Answer by J0hn4n · Nov 01, 2017 at 10:57 PM

I am actually creating textures in runtime its actually very fast and just one drawCall. I was using mesh generation but the meshes have tearing so i drop the idea.

So i am just creating a chunk with a runtime texture say 64*64 tiles if i need modify i just set pixels and apply the changes.

Comment
Add comment · Show 1 · 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 J0hn4n · Nov 01, 2017 at 10:59 PM 0
Share

Another idea i will try its a material with tiling properties

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

145 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

Related Questions

Repeat Texture instead of Stretching it all over? 4 Answers

Texture type -> Advanced -> Mesh type: how it works? 1 Answer

Split a mesh while using same UVs and texture position. 0 Answers

Texture layers on single mesh 1 Answer

Texture on Unity Meshes 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