Skip to content

Commit

Permalink
fix(Visual): prevent fade mesh getting destroyed on disable
Browse files Browse the repository at this point in the history
The movement of the mesh overlay seems to cause the component to get
disabled and then re-enabled causing the mesh to not be available
at some points, which means the fade doesn't work.

Instead of destroying the mesh when the component is disabled, it now
just disables the renderer component and makes the destroy mesh method
public so it can be manually destroyed.
  • Loading branch information
thestonefox committed Jun 24, 2021
1 parent c3b62c6 commit bed276e
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions Runtime/Visual/CameraColorOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,20 @@ public virtual void Blink()
blinkRoutine = StartCoroutine(ResetBlink());
}

/// <summary>
/// Destroys the fade mesh used in the Universal Render Pipeline. To recreate it, the component must be disabled then re-enabled.
/// </summary>
public virtual void DestroyFadeMesh()
{
if (urpFadeOverlay == null)
{
return;
}

urpFadeOverlay.transform.SetParent(null);
Destroy(urpFadeOverlay);
}

protected virtual void OnEnable()
{
lastUsedCamera = null;
Expand All @@ -251,10 +265,13 @@ protected virtual void OnDisable()
CancelBlinkRoutine();
if (GraphicsSettings.renderPipelineAsset != null)
{
if (fadeRenderer != null)
{
fadeRenderer.enabled = false;
}
#if UNITY_2019_1_OR_NEWER
RenderPipelineManager.beginCameraRendering -= UrpPreRender;
#endif
DestroyFadeMesh();
}
else
{
Expand Down Expand Up @@ -309,21 +326,6 @@ protected virtual void CreateFadeMesh()
mesh.uv = uv;
}

/// <summary>
/// Destroys the fade mesh used in the Universal Render Pipeline.
/// </summary>
protected virtual void DestroyFadeMesh()
{
if (urpFadeOverlay == null)
{
return;
}

urpFadeOverlay.transform.SetParent(null);
Destroy(urpFadeOverlay);

}

/// <summary>
/// Applies the given <see cref="Color"/> to the cameras via <see cref="CameraValidity"/> over the given duration.
/// </summary>
Expand Down

0 comments on commit bed276e

Please sign in to comment.