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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Defining / Saving Tile Patterns and Painting, Rotating, and Instantiating them at run time

Discussion in 'Scripting' started by Limnage, Jun 26, 2022.

  1. Limnage

    Limnage

    Joined:
    Sep 12, 2013
    Posts:
    41
    For 2D tile based games, you often need to define tile patterns, for example for area of effect spells, and then instantiate them at run time (for example to show a targeting indicator or AoE effects), sometimes rotating them first.

    For example, let's say I want to make a cone AoE pattern like so:

    upload_2022-6-26_23-29-34.png

    I want to be able to save this pattern (marking the bottom tile as the origin point of the AoE), assign it as an AoE pattern for a spell, and then when casting the spell instantiate this pattern (for example to show targeting and allow the user to choose the cone direction) and rotate it as necessary.

    Is there a way to do this with the built-in 2D tools? You can paint them into a palette and then select and paint them into the tilemap in the editor (although there doesn't seem to be a way to select just that cone pattern for a hexagonal grid because you can't shift-click to add tiles and the drag select pattern is wrong). However I can't find a way to save the pattern and then instantiate it at run time.

    Do you need to write a custom brush and brush editor for this?
     
  2. TheFunnySide

    TheFunnySide

    Joined:
    Nov 17, 2018
    Posts:
    192
    Arent Brushes editor only? I think you have to program these shapes by hand.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,779
  4. Limnage

    Limnage

    Joined:
    Sep 12, 2013
    Posts:
    41
    Yep, those two hex resources are great I've been using them as references for the game.

    So it seems like the answer is that there's no way to do this with the built-in 2D tools and you have to code up everything yourself, including the editor to define and save the tile patterns.

    That's a shame because the functionality is all there to create patterns in a palette and paint them using GridBrush in the editor, it's just missing a way to save those patterns and easily use them at run-time. I guess that's not surprising because recently Unity has been releasing lots of feature sets and then abandoning them before they're complete.