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 /
  • Help Room /
avatar image
6
Question by remydjackson · Nov 23, 2017 at 08:22 PM · tilemaptiles

I am using the new tilemap feature in unity 2017, how do I store information in a specific tile?

In my game a character can chop down trees that are represented by a tree tile that is an extension of Tilebase. I need the tree tile to have an int that refers to the number of trees left. I have a Sprite array 0-7 that shows the 8 levels of trees are present then it removes the tile after it goes below 0; For some reason the int numtrees is shared across all tree tiles in my game and is not unique to the tile. How do I give my tiles a unique numtrees and change it in game place so that the sprite changes and eventually the tile is removed?

I can remove the tile just fine using setTile method but I can not change an individual tile's numtrees and change its sprite in runtime.

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

7 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Dried09 · Jan 09, 2018 at 08:34 AM

Hi! Storing data of individual tiles is really problem, I'm stucked with it too. Whole last week I trying to find normal solution, asking people on forum\answers\stackoverflow and found out something.

First, tiles are scriptable objects, they not inherit MonoBehaviour and, roughly speaking, has a static data inside by default, because it is normal behaviour for scriptable objects in Unity. Tiles data storing in a struct TileData, which exists for each tile in a Tilemap GameObject. TileData has a "Instanced GameObject" field which may to contain regular Unity GameObject with any logic in its components what you need, Unity creates one for all tiles and will attach to Tilemap as children. BUT, I didn't find more or less normal way to get/set data in this GameObject, it's very uncomfortable to access in different ways tiles (Set/GetTiles()) and regular GameObjects. I also tried to access this GOs via Tilemap, but in this way is possible to access only scriptable object (which is "static" and share values to all).

Second, I found additional extensions for default TileMap features in Unity by, as I understand, TileMap developers. Among others it contains a GridInformation script, which looks like a some compromise solution of tiles data storing. It has no any docs\references\examples, but it looks simple. You can find it here. As I understand GridInformation script allows to get\set properties (like dictionary, key/value) by grid positions. I didn't dig deep, but as for me it's not a good solution, so many additional code to do so simple things.

I will continue to find optimal solution and will be grateful for help too.

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
1

Answer by ryandotdee · Dec 24, 2017 at 01:21 AM

I am looking for the same information. I have tried attaching a gameobject to each tile at runtime and setting / storing values on it. But I run into the same problem. I am starting to think that it it not possible, in which case I will need to make an array of objects which are storing the "state" of the tile, referenced by its cell position.

But if I am wrong I would be very keen to know the answer!

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 mbtthew · Dec 05, 2017 at 04:33 AM

Did you ever find a solution? I’m having trouble with this one as well. ,Where you ever able to solve this? I’m have the same query and can’t find a solution.

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 unity_ZXTycjh-ddLLDg · Dec 25, 2017 at 08:23 PM

Im rather new so sorry if this response is ignorant. And my apologizes but i did not use tileMap when using this script but plan too so would be glad to know it will work. however it does relate to storing individual stats in a gameObject, in this case one that is instantiated repeatably but each instantiate (clone) carries individual stats derived from the same script attached to the prefab (in OP case the Tree).

an array is used to represent each state of the tree:

 [SerializeField]
 private Transform[] difStatesOfTree;
 private int pointsToNextState;

At Start (may not be needed, probably depends on case of use)

 difStatesOfTree[0].gameObject.SetActive(true);

in the Update function (im aware there are more efficient ways of doing this, just not savvy on the use)

     if (pointsToNextState >= 1)
     {
         difStatesOfTree[0].gameObject.SetActive(false);
         difStatesOfTree[1].gameObject.SetActive(true);
         difStatesOfTree[2].gameObject.SetActive(false);
         difStatesOfTree[3].gameObject.SetActive(false);
         Debug.Log("difStatesOfTree Level 1");
     }
     if (pointsToNextState >= 5)
     {
         difStatesOfTree[0].gameObject.SetActive(false);
         difStatesOfTree[1].gameObject.SetActive(false);
         difStatesOfTree[2].gameObject.SetActive(true);
         difStatesOfTree[3].gameObject.SetActive(false);
         Debug.Log("difStatesOfTree Level 2");
     }
     if (pointsToNextState >= 10)
     {
         difStatesOfTree[0].gameObject.SetActive(false);
        difStatesOfTree[1].gameObject.SetActive(false);
         difStatesOfTree[2].gameObject.SetActive(false);
         difStatesOfTree[3].gameObject.SetActive(true);
         Debug.Log("upGrades Level 3");
     }


Correct me if Im wrong but if your Trees are being generated from a prefab than attaching this script to the prefab would allow you to do what you are looking for. Id have each difStatesOfTree[] as a child to an empty with the script, each child set to inactive in the inspector. Simply add a function for chop to affect the pointsToNextState. This is a rendition of one of my scripts for a project im working hope this helps.

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 RKrusty22 · Jan 13, 2018 at 10:25 PM

Also wish this was simpler or easier to access/change, I need my tiles to change sprites in a sequence upon interaction, to other specific sprites in specific positions. Was much easier to code with a plug-in (STE) but I was hoping to use the native Unity tilemaps.

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
  • 1
  • 2
  • ›

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

128 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

Related Questions

Sprites get horribly cluttered when using Tile palette 1 Answer

My Tile Palette becomes a grey mess 3 Answers

Why does my tile palette look like this ? 0 Answers

Slicing tilesets with different single image size 0 Answers

Tiles Appear All White in Unity Play Mode 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