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

Rule Tile - Copy?

Discussion in '2D' started by Welfarecheck, Oct 13, 2021.

  1. Welfarecheck

    Welfarecheck

    Joined:
    Jun 14, 2020
    Posts:
    117
    Is there a way to copy a rule tile and assign a different sprite sheet to it? I have a set of 30 sprite sheets and I need a way to simply select a new image. All sliced sheets have the exact same index like blue_3 is the same as _Red_3.

    As it is now, you can copy the rules to a new one, but you have to manually set each sprite and I really don't want to do that 48 X 30 times.
     
    TreeHacks likes this.
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Unfortunately, not automatically, but it looks like something that we should be able to do. We will add this to our backlog and see how to go about this.
     
    TreeHacks likes this.
  3. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,503
    @ChuanXin If it is possible, could the API for preserving sprite references in the Editor be opened up and better documented? Similarly to OP, I had a situation where I wanted to copy and then swap a bunch of sprite references but I wasn't sure that I was doing it right and it seemed overly complicated (asset GUID + string name) then manually scan and replace references. It made me wonder if there's a better/cleaner tool. Perhaps I'm just not familiar with those parts of the API?
     
  4. Welfarecheck

    Welfarecheck

    Joined:
    Jun 14, 2020
    Posts:
    117
    Awesome!

    Another thought, I think a grid layout that corresponds to the sliced sprite sheet indexes would be a lot better too instead of a vertical list. I know for myself, seeing all the parts on the screen at once is a lot easier than trying to scroll through items vertically.

    Something like this maybe and then tiny nodes in a corner for collider, object, and output.
    upload_2021-10-14_8-51-11.png

    Thank you!
     
    TreeHacks likes this.
  5. Xiangting_Su

    Xiangting_Su

    Unity Technologies

    Joined:
    Sep 22, 2020
    Posts:
    253
    Thank you for letting us know of your use case! Like ChuanXin mentioned, this sounds worthy of an exploration.

    I've got a basic question, are your 30 Spritesheets related in some ways since they share the same layouts/indices? Are they terrain variations by any chance? I'm curious to understand more about your workflow so that we can further optimise Rule Tiles setup in consideration of all other use cases. Thank you! :)
     
    TreeHacks likes this.
  6. Zephus

    Zephus

    Joined:
    May 25, 2015
    Posts:
    356
    I think I know exactly what he means, and I actually have the same request. Take these tilesets for example:



    They are pretty much just variations of each other. I drew one 'base tileset' and then changed colors and added details to create new tilesets. Most of the tiles are in exactly the same spot. There are a few differences though as the first one has more objects in the top rows.

    So now I have to slice one of the spritesheets, create physics shapes for the colliders, create tile objects, and then set up all of the rule tiles. So far, so good. But now the problems with the current workflow surface in a big way. The other spritesheets are almost identical, but I can't copy anything over. I pretty much have to do everything again, for every single spritesheet.

    For the second one I have to create all the colliders again, which is REALLY annoying as they are the exact same from the first one. I just want to copy them over, but I can't. Then I have to create the tile objects again, and now it gets really tedious. This is also what the opening post meant. I'll create a rule override tile, and for every single rule I have to swap out the old tile with the new one. But for that I have to find it first. So now I'm looking through this gigantic list of hundreds upon hundreds of tiles to find the correct tile. This is so tedious and annoying. I just want to copy everything over from my old tiles.

    I'm not sure what the best way to implement this is. I feel like I want a function that lets me drag in the new spritesheet, so that it can set-up the new tiles with the exact same options. Maybe a "import settings from spritesheet" option in the Sprite Editor that copies over the slicing (with a new name, since the new sprites should not be called snow_0, snow_1 etc., but dirt_0, dirt_1...) and the physics shapes. For the rule tiles I have no idea how this would work. But it would be great if I could drag in a different spritesheet and the rules would just be set up automatically.
     
    TreeHacks and Xiangting_Su like this.
  7. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Prior to 2021.1, for Sprites generated from a Texture, it was tied to the Texture, its importer and the name of the Sprite. In 2021.1, it is tied to the Texture, its importer and a Sprite ID, with any assets imported before 2021.1 upgraded to use a specific Sprite ID tied to the name of the Sprite.

    Could you share how you are changing the Sprite References? This would help us figure out how we can support this better!
     
  8. Welfarecheck

    Welfarecheck

    Joined:
    Jun 14, 2020
    Posts:
    117
    @xiangtingsu ; @Zephus Nailed it. They are variants of the same sheet with different colors. All of them have identical indexes.

    Example; I have "paved" and "dirt" that are the exact same sheet but different look. I want to be able to copy/paste the rule tile and then have an option for a source sprite in the window that would automatically source every rule to the new sheet with the exact same index/order as the original.

    Something like below adding an optional sprite sheet selection to the top of the rule tile window where you can use the same rules on any sheet based solely on index as long as the indexes are equal in number. It would be ideal to take no action to set it up beyond copy/paste the rule and select the sprite to use. Super simple and quick.

    upload_2021-10-21_17-55-28.png


    Thank you kindly!
     
    Xiangting_Su likes this.
  9. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    +1 For this.

    But also.. the data associated with the each tile should be expandable customizable by being able to add / remove the fields to the struct, or class. Right now, I am actually doing this, but I have to manually edit the actual editor script to display them all.
     
  10. Lahiter

    Lahiter

    Joined:
    Mar 1, 2018
    Posts:
    14
  11. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I am already using it but it has nasty bug where one of the tile does not get set correctly. I have tried to fix it but no... So I am manually doing it all over again. Not a big deal, but it would be nice if it was natively supported by Unity.
     
  12. Lahiter

    Lahiter

    Joined:
    Mar 1, 2018
    Posts:
    14
    I'm using it in a project and didn't have any problems so far. In another one I modified it a bit to allow diagonal tiles. Maybe I could help with your bug?

    But I totally agree that this should be supported by Unity natively.
     
  13. Welfarecheck

    Welfarecheck

    Joined:
    Jun 14, 2020
    Posts:
    117
    I saw that but I didn't want to redo everything to match a new template. :D I'm also not a programmer at all so I have no idea how to make it work for my needs. heh. One of those strange situations.
     
  14. Xiangting_Su

    Xiangting_Su

    Unity Technologies

    Joined:
    Sep 22, 2020
    Posts:
    253
    Hey thank you @Zephus! That's a super helpful walkthrough. There seem to be multiple issues on different levels all somewhat related to scalability for multiple Tilesets/Spritesheets. I'll feedback this to the team and let us see dig deeper on this. Thank you again! :)
     
  15. Xiangting_Su

    Xiangting_Su

    Unity Technologies

    Joined:
    Sep 22, 2020
    Posts:
    253
    Thanks @jlbaker2779! I see you have a very similar workflow as @Zephus. I also like your idea of swapping out Tilesets/Spritesheets for reusability.

    Interestingly, we are also looking at how we could improve the workflows of setting up Rule Tiles which we understand can be quite tedious and time-consuming as well. Perhaps there may be some convergence in both the Rule Tile and Rule Override Tile workflows. Thank you all for chiming in. These are really helpful! :)
     
    Last edited: Oct 25, 2021
  16. Welfarecheck

    Welfarecheck

    Joined:
    Jun 14, 2020
    Posts:
    117
    Most welcome! I'm a VS person and have no idea about any of the code so having it simple out of the box would be pretty fantastic no only for myself, but for future folks who have no plans on learning to code.

    From what I have seen there are quite a few different tilemap templates out there. Perhaps a standard template set would be a good avenue. A small set of 2-3 different templates people can use to draw what they want and simply pick the one they used from the dropdown. Of course have a custom dropdown for folks who have their own designs that don't fit a template. That would mostly eliminate the need to setup rules at all if you used one of the templates.

    Starting out, I had no idea what I was looking for or how to begin drawing them but I found this on the Lospec discord and it works great for my needs.

    https://opengameart.org/content/seamless-tileset-template-ii

    upload_2021-10-26_16-14-43.png

    My dirt (rotated 180 degrees)
    upload_2021-10-26_16-3-17.png
     
    Xiangting_Su likes this.
  17. Xiangting_Su

    Xiangting_Su

    Unity Technologies

    Joined:
    Sep 22, 2020
    Posts:
    253
    That's very true too! We are exploring different ways to help users set up these Scriptable Tiles as simply and quickly as possible and template does seem to be one good option.
     
    TreeHacks likes this.
  18. FernandoDarci

    FernandoDarci

    Joined:
    Jan 25, 2018
    Posts:
    19
    Templates are not only good, are far from the best option. Tilesets are made of different tiles, and have pre-made templates help not only to rulesets, but even to Tileset order. In Sprite Editor, the Slice tool give a solid pattern to this, since it renames each sprite with an index Top-Right based.

    An interesting solution, simple and reliable, are a Template Rule, where you set a rule for each index. Just drop the tileset into the rule and it auto-convert to a Rule Tile. Fast as hell.
     
  19. Xiangting_Su

    Xiangting_Su

    Unity Technologies

    Joined:
    Sep 22, 2020
    Posts:
    253
    Yes you made good points there, @FernandoDarci! The team is in the midst of R&D-ing the templated approach in different ways.

    Some of the key considerations would be:
    • What would be the most helpful set for our users? E.g. Blob/Wang/Fang?
      • 2x2 (16 Tiles) -> Too little?
      • 3x3 minimal (47 Tiles)
      • 3x3 (256 Tiles) -> Too many?
      • Others?
    • What Grid perspectives should we provide?
      • Side-on/Platformer
      • 3/4 Top-Down
      • Full-On Top-Down
      • Isometric
      • Hexagonal (Flat-Top/Point-Top)
      • Others?
    • What would be the preferred arrangements of these Tiles (in the Tileset) so that:
      • It's easier/faster to paint over the template
      • And also easier to visually debug the edges/seams of the Tiles.
    • What else can we help to hook up so as to ensure scalability, interoperability and iterability.

    And we'll be curious to know if you guys have any preferred templates (and why). Or if there are other considerations/details which matter to you or your productions which would be good for us to know too. Thank you! :)
     
  20. dreammix

    dreammix

    Joined:
    Feb 11, 2018
    Posts:
    2
    I made a script for this (attached below). Here's a tutorial on how to use it.
    -Just duplicate a a Rule Tile in which you want to replace it's texture.
    -Stick this script on a blank object in the scene
    -Select the "Rule Tile To Update"
    -Select the new texture in "Replace With"
    -Check the "Replace" box & it will complete the tedious work automatically.
    -Even though this method should do it automatically, uou have to change the default sprite. If you don't all changes will be unwritten after exiting Unity (I supposed because Unity thinks it's the same tile. You will know it is updated when you see the icon change in "Project".

    This only works in editor mode, but it could probably be done after building.

    Tutorial:
    tut.PNG tut2.PNG tut3.PNG
     

    Attached Files:

    Last edited: Oct 26, 2022
  21. Lexazan

    Lexazan

    Joined:
    Nov 7, 2013
    Posts:
    1
    Thanks, works great! One side note - the spritesheet you are replacing with should be in Assets/Resources/.. folder, otherwise script won't find it and you'll get "IndexOutOfRangeException" exception
     
  22. RafaelMatos_

    RafaelMatos_

    Joined:
    Mar 1, 2017
    Posts:
    3
    This works great and already saves us a ton of time. One thing that is missing is the multiple outputs support. Right now it only works for single output. Would you consider adding this? I'd pay for your time and anyone could use this script too