xxxxxxxxxx
// Most likely a bounding box that is not updated,
// if the mesh is generated at runtime via shader or code
// Use a script to update the bounding box
xxxxxxxxxx
using UnityEngine;
// Component to put on your mesh
public class OverrideBounds : MonoBehaviour
{
public Vector3 Center;
public Vector3 Size;
public void CreateUpdatedMesh()
{
var meshFilter = GetComponent<MeshFilter>();
var meshCopy = Instantiate(meshFilter.sharedMesh);
meshCopy.bounds = new Bounds (Center, Size);
meshFilter.sharedMesh = meshCopy;
}
}
// Code by Aki Aoki
// https://medium.com/@akidevcat/volumetric-lighting-in-unity-using-shader-graph-463864ba5462
xxxxxxxxxx
using UnityEditor;
using UnityEngine;
// Custom editor script to control the bounding box updater component
[CustomEditor(typeof(OverrideBounds))]
public class OverrideBoundsEditor : Editor
{
public override void OnInspectorGUI()
{
var component = (OverrideBounds)target;
DrawDefaultInspector();
if (GUILayout.Button("Create Updated Mesh"))
{
component.CreateUpdatedMesh();
}
}
}
// Code by Aki Aoki
// https://medium.com/@akidevcat/volumetric-lighting-in-unity-using-shader-graph-463864ba5462