So I have a bit of a weird system in my game where I sometimes need to use tiles that have all their sprites have a different pivot with a configurable offset. The way I’m doing this is, if I need to set an offset tile, I instantiate the base tile, go through all the base tile’s sprites, create new sprites using their texture rects but with the new offset pivot, assign these new sprites to the new tile, and set this tile on the tilemap needed. I’m also caching the different versions in a dictionary so that I only create 1 tile per specific offset needed. The reason I have to go through this trouble instead of just placing the tiles in different cells is because the cell position cannot change so that Y-sort rendering doesn’t break.
This seems to work fine but, if let’s say I’m using offsets of 0, +3, and +6, the first time I instantiate a tile with a +3 offset, all newly cloned tiles after this moment, even if they have a 0 offset, get offset by 3 in the game and scene views. Yet if I check via debug log the new tile’s sprites have a correct 0 offset pivot! Then, the first time I instantiate a +6 offset tile, all new tiles after this moment, whether they are 0, +3, or +6 tiles, will show with a +6 offset in game. Not only this, but if I move any of these cloned tiles in the scene view, if they wre showing as having a +3 offset for example, they immediately change to +6 offset once I move them.
This leads me to believe that the tilemap or tilemap renderer component must have some internal dictionary to quickly access tiles or sprites, and it’s overwriting the old tiles or sprites, maybe because they all share some property that it accesses them by? I tried making sure they all have unique names but that did not fix it.
My tiles are either of type RuleTile or RuleOverrideTile. For RuleTile tiles, I am instantiating the base tile, creating a new sprite and assigning it to m_DefaultSprite, creating a new m_TilingRules list, cloning each TilingRule from the base tile and adding it to this new list, and creating a new sprite for each new TilingRule object. For RuleOverrideTile, I am again instantiating the base tile, creating a new m_Sprites list, creating new TileSpritePair objects in this new list, assigning the same sprite as in the base TileSpritePair’s m_OriginalSprite while creating a new sprite for m_OverrideSprite. I am then calling the Override() method. Everything seems to be working correctly except this one sprite offset issue.
Not sure if this is even a bug, limitation, or just something I’m doing wrong. Has anyone ever worked with something like this and knows what’s going on and how to get around this issue please?