diff --git a/unity-client/Assets/Scripts/MainScripts/DCL/Components/Avatar/BodyShapeController.cs b/unity-client/Assets/Scripts/MainScripts/DCL/Components/Avatar/BodyShapeController.cs index 1a9735e2e6..d56417699b 100644 --- a/unity-client/Assets/Scripts/MainScripts/DCL/Components/Avatar/BodyShapeController.cs +++ b/unity-client/Assets/Scripts/MainScripts/DCL/Components/Avatar/BodyShapeController.cs @@ -53,6 +53,12 @@ public void SetActiveParts(bool lowerBodyActive, bool upperBodyActive, bool feet public void SetupEyes(Material material, Texture texture, Texture mask, Color color) { + if (assetContainer?.transform == null) + { + Debug.LogWarning("Tried to setup eyes when the asset not ready"); + return; + } + AvatarUtils.MapSharedMaterialsRecursively(assetContainer.transform, (mat) => { @@ -66,6 +72,12 @@ public void SetupEyes(Material material, Texture texture, Texture mask, Color co public void SetupEyebrows(Material material, Texture texture, Color color) { + if (assetContainer?.transform == null) + { + Debug.LogWarning("Tried to setup eyes when the asset not ready"); + return; + } + AvatarUtils.MapSharedMaterialsRecursively(assetContainer.transform, (mat) => { @@ -88,6 +100,12 @@ public override void SetAssetRenderersEnabled(bool active) public void SetupMouth(Material material, Texture texture, Color color) { + if (assetContainer?.transform == null) + { + Debug.LogWarning("Tried to setup eyes when the asset not ready"); + return; + } + AvatarUtils.MapSharedMaterialsRecursively(assetContainer.transform, (mat) => { diff --git a/unity-client/Assets/Scripts/MainScripts/DCL/Components/Avatar/WearableController.cs b/unity-client/Assets/Scripts/MainScripts/DCL/Components/Avatar/WearableController.cs index 5d6227ce30..a714cc201b 100644 --- a/unity-client/Assets/Scripts/MainScripts/DCL/Components/Avatar/WearableController.cs +++ b/unity-client/Assets/Scripts/MainScripts/DCL/Components/Avatar/WearableController.cs @@ -64,7 +64,10 @@ public virtual void Load(Transform parent, Action onSuccess, void OnSuccessWrapper(GameObject gameObject) { - loader.OnSuccessEvent -= OnSuccessWrapper; + if (loader != null) + { + loader.OnSuccessEvent -= OnSuccessWrapper; + } assetRenderers = gameObject.GetComponentsInChildren(); PrepareWearable(gameObject); onSuccess?.Invoke(this); @@ -73,8 +76,12 @@ void OnSuccessWrapper(GameObject gameObject) void OnFailEventWrapper() { - loader.OnFailEvent -= OnFailEventWrapper; - loader = null; + if (loader != null) + { + loader.OnFailEvent -= OnFailEventWrapper; + loader.ClearEvents(); + loader = null; + } onFail?.Invoke(this); } loader.OnFailEvent += OnFailEventWrapper;