Answers inline below. Screenshot of inspector and the problem attached:
Your code copies the relative and absolute values, but where is the code that actually sets the anchoring?
The anchor targets are set in the object hierarchy. "horizontal" and "vertical" have the same frame of reference as each "tile," and that never changes, so I handle it there.
Do you actually have one widget anchored to another? Because this is not shown here.
I double and quintuple checked: "horizontal" and "vertical" do indeed have anchor targets, and they are indeed precisely the same as a tile's.
Furthermore I am not sure what this "Tile" is, or what values you get from doing your math there.
The game uses a 6x6 grid of tiles to make the board. The intent of the feature is that "horizontal" and "vertical" highlight rows and columns of tiles by overlaying themselves on top of them. This is to indicate the tile on which the player is about to place a piece.
For the "vertical" piece, for example, if we're trying to highlight a tile in the 4th column out of 6 (index 3), we would get:
- Left anchor relative = 0.5 (center)
- Right anchor relative = 0.666666666667
This would position the asset at 1/6th the board width, starting 1/2 way across, to highlight the 4th row.
I have double and quintuple checked that the numbers I get on the anchors (in real-time) are consistent with themselves, the tiles' anchors, and my own math
Why are you doing any of this in the code anyway? Why can't you set it up in inspector?
I'm doing this in code because it changes in real-time. It's an input-feedback feature, highlighting one of the 36 tiles while the player's finger is over it, changing while they move.
Funny you should ask though: When I play around with these values on these assets in the inspector without the game running,
I get the same behavior. If I set the left and right anchors of "vertical" both to 0.5 (center), the asset stays an absolute width. I can't make it shrink smaller than it "wants to," even in the inspector.
I've attached an image showing what I'm talking about.
- "vertical" is anchored to boardTilesContainer, which occupies all of the empty space in the center of the screen. You can see that "vertical" should be flush with the top and bottom, and isn't.
- You can see that "vertical" should have 0 width, and yet it doesn't.
- Aspect Ratio is set to "free," and isn't conforming to the dimensions I'm setting. Never seen anything like this before.