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. Dismiss Notice

Tilemap to prefab

Discussion in '2D' started by Paykoman, Nov 7, 2019.

  1. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    Hi guys, i have a random dungeon generator that i usually use with 3d prefabs, but now i create some 2D rooms with tilemap and i want to know how can i convert the tilemap into prefabs to use in level generator, because if i simply drag it into Prefabs folder, only appears the single tiles i use and not the entire map.
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @Paykoman

    Why not convert your tilemap rooms to to a 2D array of ints for example? Then you could feed those to your level generator as rooms data?
     
    SpiritRaG likes this.
  3. PuppyPolice

    PuppyPolice

    Joined:
    Oct 27, 2017
    Posts:
    116
    you mean you have multiple tilemaps and want to have a single prefab for all of em? In that case why not parent them all to a single gameobject and prefab that then just instantiate the gameobject when needed?
     
  4. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    The map generator is ready to simply instantiate random premade rooms, so thats why i want it like that.. the other problem is that i need to keep the tile colliders and i don't think thats possible, cuz if i create a prefab from a level it dont retain the tille collider i have, and creating a new one if dont match the map form...
     
  5. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    I dont think im explaining well.. i will have 1 tile for example like a 2D square that i paint from it a room with Tile Pallete, as i paint the level it generate the colliders, so that room is ready to play, and i want to create a prefab out of that level with the colliders ready so i can instantiate it, but if i simply drag it into prefab folder the colliders disapear.
     
  6. PuppyPolice

    PuppyPolice

    Joined:
    Oct 27, 2017
    Posts:
    116
    So where is the collider you generate? I assumed you were using the tilemap2dcollider that you attach to your tilemap which should follow when prefabed.
     
  7. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    I thought the same, but i will test tomorrow again. I have to save the grid main folder as well or i just need to prefab the tilemap?? Appreciate man
     
  8. PuppyPolice

    PuppyPolice

    Joined:
    Oct 27, 2017
    Posts:
    116
    You gonna need a grid component if you gonna use tilemaps, so make sure you prefab your tilemaps with a parent that has a grid component, or make em a child to a gameobject with a grid when you instantiate em
     
  9. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    I tested out and i probably have to create the collider manually, and them create the prefab, that way the collider stays together. Just need to check the map generator now and see if it works properly like with 3d objects
     
  10. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    I work, but the 3d script for random dungeon dont work with 2D assets... -.-"