Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Commit

Permalink
Added null safe checks to avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
AjimenezDCL committed Oct 19, 2020
1 parent e351277 commit 62c7df4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
{
Expand All @@ -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) =>
{
Expand All @@ -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) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public virtual void Load(Transform parent, Action<WearableController> onSuccess,

void OnSuccessWrapper(GameObject gameObject)
{
loader.OnSuccessEvent -= OnSuccessWrapper;
if (loader != null)
{
loader.OnSuccessEvent -= OnSuccessWrapper;
}
assetRenderers = gameObject.GetComponentsInChildren<Renderer>();
PrepareWearable(gameObject);
onSuccess?.Invoke(this);
Expand All @@ -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;
Expand Down

0 comments on commit 62c7df4

Please sign in to comment.