Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Drawing pre-made rooms with the tile palette

Discussion in '2D' started by Emolk, Sep 11, 2019.

  1. Emolk

    Emolk

    Joined:
    Feb 11, 2014
    Posts:
    241
    Hi. I'm making a 2D procedural generated platformer similar to Terraria.

    I'm trying to work out how to design different buildings, combat encounters etc for my game.

    Currently i use perlin noise to generate the (randomly generated) terrain using SetTile to set each block

    Now i want to add things like spawner rooms, underground houses etc to make my world more lively.

    Since my world is randomly generated on world creation, i can't just draw the tiles on the scene itself.

    I'm trying to figure out how i can save a tile palette drawing, instead of designing the rooms by hand and then coding them in?

    Specifically, i want to be able to use the tile palette to draw a room on my scene, then 'save' that room so i can then generate that room into the world? If i can't do that, is there another way to design 'rooms' then generate/spawn them into the world?

    Cheers.
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    If you have drawn a room into a Tilemap, could you get the Tiles which make up the room and save this set of Tiles with their relative positions? You can then set this set of Tiles using the same SetTile API.

    Alternatively, if the room contains more than just these Tiles, you could make a room as a GameObject/s and turn it to a prefab, and instantiate this prefab when you require them?
     
    Emolk likes this.
  3. Emolk

    Emolk

    Joined:
    Feb 11, 2014
    Posts:
    241
    Oh damn why didn't i think about that! Draw the room and then save the tiles, smart. So i would create a new tilemap, draw the tiles on there then are runtime save their positions, then delete the tilemap correct?

    For your second paragraph, how would i connect the tiles to the prefab? As in how do i, when spawning the prefab, spawn the tiles? Save the positions then on start() in the prefab draw the tiles?
     
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    That would work, even in the editor.

    When you save a Tilemap GameObject as a prefab in the Editor, you will save everything about it including the Tile positions. When you spawn the prefab in runtime, all the Tiles set previously will be spawned along with the Prefab as well.