StandardBarkUI.cs crash fix if scene is shutdown
Posted: Mon Oct 26, 2020 2:10 pm
It is inefficient to check Camera.main as this searches every object in the scene for a string comparison. Reduced to a single check
Camera.main can return null while the scene is shutting down
Camera.main can return null while the scene is shutting down
Code: Select all
protected virtual void Update()
{
if (keepInView && isPlaying)
{
// KevinJ: Check camera.main
Camera mainCamera = Camera.main;
if (mainCamera != null)
{
//var pos = Camera.main.WorldToViewportPoint(canvas.transform.position);
var pos = mainCamera.WorldToViewportPoint(canvas.transform.position);
pos.x = Mathf.Clamp01(pos.x);
pos.y = Mathf.Clamp01(pos.y);
//canvas.transform.position = Camera.main.ViewportToWorldPoint(pos);
canvas.transform.position = mainCamera.ViewportToWorldPoint(pos);
}
}
}