Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 PhotonPotatoDev · Apr 27, 2021 at 10:56 PM · unity 2dtilemaptilesetcolor

SetColor() In Tilemaps Isn't Working.

Hey everyone, I was hoping that someone can help me with this problem I am having with Tilemap.SetColor(). For me, this function isn't working to set the color of the tiles. I have read through some things saying to set the tile flags to none, and that hasn't worked. I have also tried to use the Tilemap.RemoveTileFlags() function as you can see in the commented out code below.

     public void calcLighting(int x, int y, int lightingDist, int increments)
     {
         //Check if the block that we are checking is empty.
         if (!isInWorld(x, y)) return;
         if (worldBlocks[y, x] == null) return;
 
         Vector3Int thisPos = new Vector3Int(x, y, 0);
 
         //Then check all the blocks within a certain radius.
         for (int d = 0; d < 360; d += increments)
         {
             for (int dist = 0; dist < lightingDist; dist++)
             {
                 int newX = Mathf.RoundToInt(Mathf.Cos(d) * dist) + x;
                 int newY = Mathf.RoundToInt(Mathf.Sin(d) * dist) + y;
 
                 if (!isInWorld(newX, newY)) continue;
 
                 if (worldBlocks[newY, newX] == null)
                 {
                     int newLightLev = 0;//1 - (dist / lightingDist);
 
                     Color lightingColor = new Color(newLightLev, newLightLev, newLightLev);
 
                     savedChunks[getChunk(new Vector2Int(x, 0))].chunkTilemap.SetTileFlags(thisPos, TileFlags.None);
                     //savedChunks[getChunk(new Vector2Int(x, 0))].chunkTilemap.RemoveTileFlags(new Vector3Int(x, y, 0), TileFlags.LockColor);
 
                     savedChunks[getChunk(new Vector2Int(x, 0))].chunkTilemap.SetColor(thisPos, lightingColor);
                     savedChunks[getChunk(new Vector2Int(x, 0))].chunkTilemap.RefreshTile(thisPos);
 
                     if (x == 0) Debug.Log("Column" + y + " light level: " + savedChunks[getChunk(new Vector2Int(x, 0))].chunkTilemap.GetColor(thisPos).r + " wanted: " + lightingColor.r);
                 }
             }
         }
     }

I would have added the whole script for you all but it is around 700 lines long and none wants to read through all of that (let me know if I should post the whole script). This is a segment of code from a 2D procedural world generation script that I made to generate something like this: alt text

Back to the code, the function "isInWorld" takes 2 coordinates (an x and a y) and checks if that position is within the boundaries of the generated world.

The array "worldBlocks" stores variables of a custom class that just stores some data for each place in the generated world.

The array "savedChunks" is of a custom class that I made that just stores a Tilemap (among other things) that can be loaded in or out for game optimization.

If a cell in "worldBlocks" is equal to "null", that just means that it is an empty air block on the map.

Anyways the Debug at the bottom of the code returns "Column [yes, I understand that I should have labeled it row instead of column] (y coordinate) light level: 1 wanted [color]: 0"

I honestly have no idea why this isn't working, and have spent around 7-10 hours just making no progress. I would be SO grateful if anyone could help! Thank you!

Edit: The for loops that the debug is embedded in are used to basically run through all (or most) of the blocks in a circular area around the specified "x" and "y" coordinates. The radius of this area is specified by the "lightingDist" variable.

2d-procedural-game-pc-mac-linux-standalone-unity-2.png (251.1 kB)
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

166 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

Related Questions

2D tilemaps - separation of view and data, prototyping doubts 0 Answers

Changing Size of Tilemap 1 Answer

Detaching a GameObject from a Tile at runtime 0 Answers

Remove a single tile from a tilemap 1 Answer

TileMap won't show up in 2d object in heirarchy. 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