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 TheBear · Dec 02, 2018 at 12:47 AM · tilemaptile

Removing a Tile from a Tilemap

I'm doing a little prototype with the Unity Tilemap system (using a hex grid). I wanted a highlight effect when the user moves his mover a Tile and thought the easiest way would be to just layer another Tilemap over the ground.

So when the user moves his mouse over a Tile I simply need to:

 a) Remove the TileBase from the previous Tile (if any)  
 b) Set the TileBase on the new Tile  


Problem is that Tilemap doesn't have a ClearTile or RemoveTile method. It has a ClearAllTiles() method but that does some extra things I'd like to avoid, also it might not be applicable to use in all scenarios.

What works is calling SetTile with null like so SetTile(position, null). Now the documentation says nothing about this... All it says is
Sets a tile at the given XYZ coordinates of a cell in the tile map.

So I'm wondering if the is the "correct" way to do it or if there's something I'm missing?

Comment
Add comment · Show 1
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 ecv80 · Dec 03, 2018 at 10:04 AM 0
Share

For all I could read in the forums that seems to be the right way to do it. But I can't either confirm it. The documentation in those regards is really poor...

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Minespeed1009 · Jun 10, 2020 at 04:59 AM

Ok, so I looked around at what you're doing. Found out SetTile(position, null) works! Get the position by adding a grid variable and doing this:

 public Grid grid;
 public Tilemap tilemap;
 
 void FunctionToGetRidOfTile()
 {
 Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
 Vector3Int position = grid.WorldToCell(mousePos);
 tilemap.SetTile(position, null);
 }

Let me go through this. The two variables are set where grid is your Grid, and tilemap is your Tilemap. The function is to be called whenever you want to get rid of the tile. You could probably use some functions with the grid to recreate the tile somewhere else.

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

Answer by Durium · Feb 26 at 07:04 PM

Hey this actually works! Now just gotta point get the tiles location instead of mouse and we are good to go!!

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

97 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

Related Questions

3D Tile Editor? 1 Answer

tilemaps - prefab and tile issues 1 Answer

Anyone knows how to refresh tiles? 0 Answers

Tilemap color will only change to white, black, cyan, yellow or magenta. 0 Answers

Cannot assign the tile png to the tile asset file 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