Quantcast
Channel: Questions in topic: "crash"
Viewing all articles
Browse latest Browse all 2383

Game crashes on Android if manipulating Animator

$
0
0
Hi all :-) My Unity 2D game crashes (closes without error) on Android if I'm manipulating Animators/Animation Clips by script. We're using sprite animations on our main avatar and we've implemented different costumes for it. Our first approach was to create a new animator for each costume and switch those animators on runtime. When we used this approach the game wasn't even starting anymore on Android (just using the class "RuntimeAnimatorController" made it crash without an error message in logcat). Then we changed the approach an tried to override the AnimationClips in the animator - now the game starts, but crashes if we change the costume in the game.Everything works fine in Unity Editor. Here's the code for the current approach: public class PlayerCostume : MonoBehaviour { public AnimatorContainer[] costumes; private List costumeOrder = new List() { "florin", "sunglasses", "cap", "mask", "pants", "flowers", "watch", "shoes", "hat" }; void Start() { Debug.Log("Changing costume"); costumes = costumes.OrderBy(x => costumeOrder.IndexOf(x.gameObject.name)).ToArray(); int costumeIndex = Settings.GetInt(SettingKeys.SELECTED_SHOP_ITEM, 0); AnimatorContainer animatorContainer = costumes.ElementAt(costumeIndex); if (GameSystem.instance.gameType == GameSystem.GameType.HORIZONTAL) { foreach (Transform child in transform) { Animator animator = child.GetComponent(); processAnimator(animatorContainer, animator); } } else { processAnimator(animatorContainer, GetComponent()); } } private void processAnimator(AnimatorContainer animatorContainer, Animator animator) { AnimatorOverrideController overrideController = new AnimatorOverrideController(animator.runtimeAnimatorController); animator.runtimeAnimatorController = overrideController; AnimationClipOverrides overrides = new AnimationClipOverrides(overrideController.overridesCount); overrideController.GetOverrides(overrides); foreach (AnimationClip clip in overrideController.animationClips) { overrides[clip.name] = animatorContainer[clip.name]; } overrideController.ApplyOverrides(overrides); } } Logcat doesn't show any messages regarding this issue (Logging is set to full for all Log-Types). Log output attached. Unity Version 2020.1.16f1 - 2020.2.2f1 Android Version 10 [link text][1] This issue drives me crazy - help is highly appreciated :-) Thanks in advance Felix [1]: /storage/temp/175234-logcat-idg.txt

Viewing all articles
Browse latest Browse all 2383

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>