I’m trying to use BoundBox component for my project.
When I attach BoundBox using inspector it works fine.
But when I try to attach it to a generated cube, using script, the cube gets created and shows the BoundBox component under inspector but doesn’t actually work.
void CreateBox(int x, int y) {
GameObject box = GameObject.CreatePrimitive(PrimitiveType.Cube);
box.transform.parent = PlayArea.transform;
box.transform.position = GetPositionByIndices(x, y);
box.transform.localScale = new Vector3(50f, 50f, 50f);
box.layer = box.transform.parent.gameObject.layer;
box.GetComponent<Renderer>().enabled = false;
box.AddComponent<BoundBox>();
}
What could be wrong?
“Doesn’t actually work” in what sense? Bounding boxes don’t actually do anything.
I’ve a Camera with the DrawLines component and a Cube (not generated using Script) with BoundBox. This works perfectly in editor and game view. It renders the colored edges.
When I try to have the Cube generated using Script, it has the component and is rendered and all. But the edges are missing.
I have many questions, but let’s start with
- What is this “DrawLines” component you’re talking about?
- What is BoundBox, for that matter? (Neither of these is a standard Unity component.)
- What does your BoundBox look like in the inspector?
EDIT: Oops, I see you linked to the BoundBox asset in your original post. I still have no idea what it is or how it works, though…
BoundBoxes is an add-on component from the asset store. See Link.
It comes with the DrawLines component and the Boundbox component. DrawLines are attached to a Camera and BoundBox are attached to the object that needs to show bounding boxes.
This is what it looks like with and without the Mesh Renderer components.

