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 Arisstephenson · Jul 14, 2018 at 12:06 AM · 2darraycoroutinetilemaptiles

Array of Tilemaps misbehaving

I am creating a script that generates a 2d array of Tilemaps and then runs a specific function on them that will create "caves" with a Perlin function. It was only showing up on the top left Tilemap, so I tried to see where the function was actually working by making it remove all tiles it passes over and this is what I got. alt text The result I was expecting was all of the tiles to be gone. Why aren't they??


Here is the code:

At the beginning of my script I set CHUNKSIZE to 64 and define currentChunk as null. GenerateWorld is called first.

 public void GenerateWorld()
     {
         StartCoroutine("CreateChunks");
     }

Then it runs this function.

     IEnumerator CreateChunks()
     {
         chunks = new Tilemap[Mathf.CeilToInt(xCount / CHUNKSIZE), Mathf.CeilToInt(yCount / CHUNKSIZE)];
         for (int x = 0; x < xCount; x++)
         {
 
             for (int y = 0; y < yCount; y++)
             {
                 if (x % CHUNKSIZE == 0 && y % CHUNKSIZE == 0)
                 {
                     GameObject current = new GameObject();
                     current.transform.position = new Vector3Int(x, y, 0);
                     //Sets parent here and sets up Tilemaps components
                     chunks[x / CHUNKSIZE, y / CHUNKSIZE] = current.GetComponent<Tilemap>();
 
                     yield return null;
                 }
             }
         }
         StartCoroutine("CreateCaves");
     }

Finally it runs this function.

     IEnumerator CreateCaves() {
         //float rand = Random.value;
         for (int x = 0; x < xCount; x++)
         {
             for (int y = 0; y < yCount; y++)
             {
                 if ((int)x % CHUNKSIZE == 0 && (int)y % CHUNKSIZE == 0)
                 {
                     currentChunk = chunks[(int)x / CHUNKSIZE, (int)y / CHUNKSIZE];
                     yield return null;
                 }
                 currentChunk.SetTile(new Vector3Int(x, y, 0), null);
 
                 //if (Mathf.PerlinNoise(x / xCount * 100 + rand * 200000, y / yCount * 100 + rand * 200000) > 0.5F)
                 //{
                 //}
             }
         }
     }


screen-shot-2018-07-13-at-50444-pm.png (80.2 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GMihai · Aug 24, 2018 at 02:12 PM

You need to refresh the tile after setting it : currentChunk.RefreshTile(new Vector3Int(x, y, 0));

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

194 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

Related Questions

Need help finding a library/solution for efficient 2D tilemap rendering, collisions and interaction. 1 Answer

why is unity set tile not working? 0 Answers

Problem with prefabs and offset 1 Answer

LWRP 2D Renderer: Tiles invisible in Tile Palette 2 Answers

Can isometric tiles be rotated? 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