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 dahui58 · Apr 14, 2020 at 02:30 PM · unity 5tilemapgridtilegrid based game

How to stack components on a Tile/Tilemap

I'm creating a Hex based grid game, I thought the Hex Tilemap would be an obvious fit for this.

Creating the initial grid was easy enough, but now I'm trying to stack things on top of individual tiles, and being pretty new to Unity, I'm finding this difficult. I've seen lots of tutorials for how to simply draw a Tilemap/grid, or lots of tutorials using the Palette, but I'd like to do this entirely through code.

My current solution is to pass in two separate Tilemaps, belonging to the same grid. I use the bottom tilemap (named Floor) for placing the floor/terrain tiles. On the second Tilemap I'm trying to place some icons or text as a status type layer. These will exist on every single tile.

     // This is a grid I've passed through into the Script from the Unity IDE  
     public Grid grid;
     // These two Tilemaps also exist in the editor as children to the Grid and are also passed in.
     public Tilemap floor;
     public Tilemap statusOverlay;
 
     // Start is called before the first frame update
     void Start()
     {
         // LoadSprites loads the floor and status tiles into a Sprite[], it works, so is not totally relevant to this question.
         LoadSprites();
         for (var xd = 0; xd <= 10; xd++)
         {
             for (var yd = 0; yd <= 10; yd++)
             {
                 var currentPos = new Vector3Int(xd, yd, 0);
 
                 // Set tile type/floor image
                 var floorTile = ScriptableObject.CreateInstance<Tile>();
                 int floorSpriteIndex = Roll(floorSprites.Length)-1;
                 floorTile.sprite = floorSprites[floorSpriteIndex];
                 floor.SetTile(currentPos, floorTile);
 
                 // Add another tile which should just add a simple icon for now.
                 var statusOverlayTile = ScriptableObject.CreateInstance<Tile>();
                 statusOverlayTile.sprite = statusSprites[1];
                 statusOverlay.SetTile(currentPos, statusOverlayTile);
             }
         }
     }


In the future I will need to add more items on top of the same grid, e.g. Units, maybe buildings, etc.. These will not be on every Tile but a subset of the Tiles.

Is this current approach good, performance wise?

I think it potentially makes sense to have a Tilemap for the Floor and Players, but maybe not so much for the Status tilemap, which will have a Tile for every single Floor tile. For this it would be good if I could either directly draw the status icons/text onto the floor Tiles, dynamically. Or create some sort of grid floor component which both draws the Floor, the status affects, and anything else in the future that might belong to a Tile itself.

Or is it not much of a performance issue to create/maintain double the amount of tiles, let's say if I scale up to thousands of tiles in the future.

FYI I think this is on unity 4.5, according to Unity > Help > About Unity

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.

Follow this Question

Answers Answers and Comments

225 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Grid and or Tile System 0 Answers

How can I compare two tilemaps by color? 1 Answer

How can i make the Unity2d grid use rounded numbers? 1 Answer

How do you find adjacent tiles of the same type in grid array [x,y].type == [x+1,y].type 0 Answers

How can I access to a tile properties in a Tilemap? 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