I’m trying to implement a click-and-drag selection feature to select tiles. Everything works except this part to show the selected tiles with a change in the tilemap upon releasing Mouse1.
I’ve debugged some and know Startpos and EndPos are correct and defined elsewhere in the code. Min-max bounds are set correctly, but the tiles aren’t set at all. If I click and drag from certain directions I end up with a negative bounds size, which may be a factor, but it doesn’t set correctly even when making sure the size of the bounds is positive. SelectionObject and in turn SelectionMap are set correctly in the editor. Layer order wouldn’t hide the tiles with current settings. What am I missing?
Bounds can be finicky - sometimes it’s just an off-by-one problem. You may need to simply add 1 to your width/height, or have a z-size/depth of at least 1.
First, however, the negative bounds needs to be fixed, so extract minX, minY from your two positions manually and obtain the width and height too - instead of SetMinMax with the raw click and release positions.
I added a debug line above the SetTile line and found the “pos” Vector3Int wasn’t being passed into the foreach function because the debug console wouldn’t display anything. So SetTile isn’t the problem. This is weird cause my syntax matches the documentation for allPositionsWithin with a foreach loop so I don’t know why that would be happening.
You may want to ensure that SelectionBounds.size.z has at least a size of 1. If StartPos.z and EndPos.z are both 0, the size would be 0 and SelectionBounds.allPositionsWithin would not loop.