The scale / width / height / position values are the same as what is initially in the atlas.
Changing the values when creating a new attachment, even to the same values as what is in the atlas, breaks the alignment.
This must mean I'm doing something wrong, possibly in the wrong order? Any thoughts on something that might point me in the right direction?
Here is the code.
Sprite spriteFromServer = Sprite.Create(newAsset.texture,
new Rect(newAsset.x, newAsset.texture.height - newAsset.h - newAsset.y, newAsset.w, newAsset.h),
new Vector2(0.5f, 1.0f),
135f);
spriteFromServer.name = newAsset.name + "_" + newAsset.placeholder;
RegionAttachment newWeapon = spriteFromServer.ToRegionAttachmentPMAClone(Shader.Find("Spine/Skeleton"));
newWeapon.X = newAsset.attachmentData.x;
newWeapon.Y = newAsset.attachmentData.y;
newWeapon.ScaleX = newAsset.attachmentData.scaleX;
newWeapon.ScaleY = newAsset.attachmentData.scaleY;
newWeapon.Rotation = newAsset.attachmentData.rotation;
newWeapon.Width = newAsset.attachmentData.w;
newWeapon.Height = newAsset.attachmentData.h;
newWeapon.UpdateOffset();
int weaponSlotIndex = skeleton.FindSlotIndex(slotName);
clonedSkin.AddAttachment(weaponSlotIndex, attachmentName, newWeapon);
skeleton.SetSkin(clonedSkin);
skeleton.SetToSetupPose();
skeleton.SetAttachment(slotName, attachmentName);
I'm not repacking the skin, because I can't find how to mark a texture loaded from the web as readable. That shouldn't be a problem, but still.
Thanks again for all the help.