I'm trying to anchor a UISprite in the UI Layer to a gameObject on a world layer in code. I've successfully done this with UILabel using SetAnchor(gameObject). In that case, I relocate the label to the same location as the world object, setting z to 0, then call SetAnchor(gameObject), followed by ResetAndUpdateAnchors(). This results in the proper unified offsets and the label in the UI layer follows the gameObject.
Doing the same thing with a Sprite has me stumped though. The 32x32 sliced sprite resizes to 2x2 (smallest possible I know) as a direct result of SetAnchor(gameObject) being called. As a result, the anchor offsets are all zero (which makes sense, given such a small sprite). I can see the now tiny sprite is in the right position, but it is too small to be useful. Interestingly, calling MakePixelPerfect() after this increases the sprite back to 32x32, but propels it to never-never land, aka enormous offsets. It is now the right size, but way off the screen.
The gameObject itself is simply an empty child GameObject of my real moving target which acts as a relative offset positioned where I want the label/sprite to be anchored.
Thanks for your excellent support. I always spend a few hours myself trying to figure these things out reading other threads before I ask.
As an aside: I can tell the anchoring system is extremely powerful and flexible, but it has a pretty steep learning curve, at least for anything more than basic concepts.