Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Question 3D Hex-Tilemap GameObjects get tile in code.

Discussion in 'World Building' started by kevinyao93, Sep 25, 2022.

  1. kevinyao93


    May 16, 2020
    I recently just started getting into unity, and what I'm attempting to do is create a simple T-RPG with a hex based grid. I was going to have each of the tiles represent a separate grid, and to create the map, I had used the 2d tilemap, and used the GameObject Brush to orient each tile.

    I've been trying to use multiple tilemaps to represent objects on the ground, and character models accordingly. I
    I was wondering how I would go ahead and be able to -

    1. Get each individual tile in the grid. (Maybe get an array of the created tiles?)
    2. Be able to mutate each tile (i.e. replace one tile with another, replacing game objects) depending on actions that are taken within the game.

    While I guess I could generate all of the tiles through code, I was hoping for a method to get and replace individual tiles. Another method I guess that could maybe work, would be creating a base map of the coords and populate the tiles for each of these, and iterating through all of the tiles, but it seems like it would end up being really inefficient and I was wondering if there was any better way to do that.

    Please let me know if I need to clear anything up.