Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to change Tilemap centre?

Discussion in '2D' started by Hydro4100, Oct 7, 2022.

  1. Hydro4100

    Hydro4100

    Joined:
    Jul 4, 2022
    Posts:
    2
    How to change Tilemap centre?

    I'm trying to make a 2D Dungeon Crawler game and want to randomly generate the dungeon. I'm designing the dungeon sections in tilemaps and want to save them as prefabs to use them when they get generated.

    I've read about connecting the tilemap to a parent object so it can link to the objects local coordinates. This works fine and I can make the prefabs. The issue lies when I place the prefab. The prefab seems to be registering a lot of blank space that I don't want.

    I was wondering if there was a way you can change either the size of the tilemap itself, or to change where the centre of the tilemap is?


    You can see the size of the tilemap when I am using the rect tool.
     
  2. DanielTanBK

    DanielTanBK

    Unity Technologies

    Joined:
    Aug 20, 2019
    Posts:
    80
    Hello,
    The rect tool shows the bounds of an object and updating that is a rather expensive operation on a Tilemap so it is not called automatically

    You could try clicking on the menu dropdown on the top right of the Tilemap Component within the Inspector and select Compress Tilemap Bounds
    Unity_76BRHrmuqs.png

    Or if you're doing it through script, you can also call the Tilemap.CompressBounds() method
     
    Last edited: Oct 10, 2022
    Regats likes this.
  3. Hydro4100

    Hydro4100

    Joined:
    Jul 4, 2022
    Posts:
    2
    Hi Daniel,
    That has worked perfectly! Thank you so much, I was scratching my head over this for 3 hours XD
     
    DanielTanBK likes this.