Really hoping that somebody can just help me make sense of this. I’m trying to make a custom handle that will act as a bounding box for the actors moving around in it. Like an animal pen. I pretty much followed the documentation for BoxBoundsHandles and made some changes to get the behavior I want. (Following the transform gizmo, etc.)
The issue is, as you’ll see in the console screenshot, that as soon as I press play, the changes I’m making to the bounds seem to reset to these values and I don’t know why.
They don’t change in the scene view, the bounding box stays the same size.Here is the code for reference (I’ve made some sloppy changes to it trying to figure out what is going on.):
[CustomEditor(typeof(Hatchery))]
public class HatcheryBounds : Editor
{
private BoxBoundsHandle m_BoundsHandle = new BoxBoundsHandle();
protected virtual void OnSceneGUI()
{
Hatchery hatchery = (Hatchery)target;
// copy the target object's data to the handle
m_BoundsHandle.center = hatchery.transform.position;
m_BoundsHandle.size = hatchery.Extents;
// draw the handle
EditorGUI.BeginChangeCheck();
m_BoundsHandle.DrawHandle();
if (EditorGUI.EndChangeCheck())
{
// record the target object before setting new values so changes can be undone/redone
Undo.RecordObject(target, "Change Hatchery Bounds");
// copy the handle's updated data back to the target object
Debug.Log("Hatchery bounds started as: " + hatchery.bounds);
Bounds newBounds = new Bounds();
newBounds.center = m_BoundsHandle.center;
newBounds.size = m_BoundsHandle.size;
hatchery.Extents = newBounds.size;
hatchery.transform.position = newBounds.center;
hatchery.bounds = newBounds;
Debug.Log("Hatcher bounds changed to: " + hatchery.bounds);
}
}
}