From 076e4e9e94004e5051517305aa320e3ad98949a2 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Mon, 21 Aug 2023 18:55:10 +0200 Subject: [PATCH] [unity] Potential fix for ArgumentOutOfRangeException at SkeletonGraphic.PrepareRendererGameObjects. See #2346. --- .../spine-unity/Components/SkeletonGraphic.cs | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs index db8f38009..759beb9b9 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs @@ -955,42 +955,52 @@ namespace Spine.Unity { int submeshCount = currentInstructions.submeshInstructions.Count; DisableUnusedCanvasRenderers(usedCount: submeshCount, isInRebuild: isInRebuild); - int separatorSlotGroupIndex = 0; - int targetSiblingIndex = 0; - Transform parent = this.separatorSlots.Count == 0 ? this.transform : this.separatorParts[0]; + Transform parent = this.separatorParts.Count == 0 ? this.transform : this.separatorParts[0]; if (updateSeparatorPartLocation) { for (int p = 0; p < this.separatorParts.Count; ++p) { - separatorParts[p].position = this.transform.position; - separatorParts[p].rotation = this.transform.rotation; + Transform separatorPart = separatorParts[p]; + if (separatorPart == null) continue; + separatorPart.position = this.transform.position; + separatorPart.rotation = this.transform.rotation; } } if (updateSeparatorPartScale) { Vector3 targetScale = this.transform.lossyScale; for (int p = 0; p < this.separatorParts.Count; ++p) { - Transform partParent = separatorParts[p].transform.parent; + Transform separatorPart = separatorParts[p]; + if (separatorPart == null) continue; + Transform partParent = separatorPart.parent; Vector3 parentScale = partParent == null ? Vector3.one : partParent.lossyScale; - separatorParts[p].localScale = new Vector3( + separatorPart.localScale = new Vector3( parentScale.x == 0f ? 1f : targetScale.x / parentScale.x, parentScale.y == 0f ? 1f : targetScale.y / parentScale.y, parentScale.z == 0f ? 1f : targetScale.z / parentScale.z); } } + int separatorSlotGroupIndex = 0; + int targetSiblingIndex = 0; for (int i = 0; i < submeshCount; i++) { CanvasRenderer canvasRenderer = canvasRenderers[i]; - if (i >= usedRenderersCount) - canvasRenderer.gameObject.SetActive(true); + if (canvasRenderer != null) { + if (i >= usedRenderersCount) + canvasRenderer.gameObject.SetActive(true); - if (canvasRenderer.transform.parent != parent.transform && !isInRebuild) - canvasRenderer.transform.SetParent(parent.transform, false); + if (canvasRenderer.transform.parent != parent.transform && !isInRebuild) + canvasRenderer.transform.SetParent(parent.transform, false); - canvasRenderer.transform.SetSiblingIndex(targetSiblingIndex++); - RectTransform dstTransform = submeshGraphics[i].rectTransform; - dstTransform.localPosition = Vector3.zero; - dstTransform.pivot = rectTransform.pivot; - dstTransform.anchorMin = Vector2.zero; - dstTransform.anchorMax = Vector2.one; - dstTransform.sizeDelta = Vector2.zero; + canvasRenderer.transform.SetSiblingIndex(targetSiblingIndex++); + } + + SkeletonSubmeshGraphic submeshGraphic = submeshGraphics[i]; + if (submeshGraphic != null) { + RectTransform dstTransform = submeshGraphic.rectTransform; + dstTransform.localPosition = Vector3.zero; + dstTransform.pivot = rectTransform.pivot; + dstTransform.anchorMin = Vector2.zero; + dstTransform.anchorMax = Vector2.one; + dstTransform.sizeDelta = Vector2.zero; + } SubmeshInstruction submeshInstructionItem = currentInstructions.submeshInstructions.Items[i]; if (submeshInstructionItem.forceSeparate) {