Hi,
I'm trying to use Spine animations in the UI of a Unity game, using SkeletonGraphic and I simply can't get it to work and fail even to understand what's going wrong.
I read the few threads where similar questions were asked already and, by now, I probably tried every imaginable combination and order for calling Update/UpdateMesh/MatchRectTransformWithBounds and setting sizeDelta etc.
What I'm trying to do is - I have a UI with a panel to show details of a user selected Unit. The panel is inside a bigger prefab and already contains the SkeletonGraphic component to show the unit.
I want the Units to be scaled using the FitInParent mode and to be centered within the panel.
When the user selects a Unit, I lookup the required SkeletonDataAsset and try to show it using the code basically given in 2 other threads in this forum.
var skeleton = AnimationManager.instance.GetSpineSkeleton(unitPrototype.excelId);
if (skeleton != null)
{
skeletonGraphic.skeletonDataAsset = skeleton;
skeletonGraphic.startingAnimation = "idle";
skeletonGraphic.startingLoop = true;
skeletonGraphic.Initialize(true);
skeletonGraphic.Update(0f);
skeletonGraphic.UpdateMesh();
skeletonGraphic.MatchRectTransformWithBounds();
skeletonGraphic.layoutScaleMode = SkeletonGraphic.LayoutMode.FitInParent;
skeletonGraphic.rectTransform.anchoredPosition = Vector2.zero;
skeletonGraphic.rectTransform.sizeDelta = Vector2.zero;
}
What I get, as the result, is a Spine animation that doesn't match the rect and, when I repeat the code, the size of the rendered Spine animation toggles between two wrong sizes. Doesn't matter if I toggle the same SkeletonData or switch to different ones.
I recorded a short gif showing the scene/inspector view - very low fps for a small file size but enough to see the problem. The Spine animation also seems to be displaced wrt to it's own rect transform.
Unity is 2022.3.14f
Spine Unity Runtime 4.1.42
Any idea what's causing this/what I'm doing wrong?
Thanks a lot