Search Unity

BoundBox not working after being attached to GameObject using script

Discussion in 'Getting Started' started by codenamed52, Apr 16, 2019.

  1. codenamed52

    codenamed52

    Joined:
    Apr 2, 2019
    Posts:
    4
    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.

    Code (CSharp):
    1. void CreateBox(int x, int y) {
    2.         GameObject box = GameObject.CreatePrimitive(PrimitiveType.Cube);
    3.         box.transform.parent = PlayArea.transform;
    4.         box.transform.position = GetPositionByIndices(x, y);
    5.         box.transform.localScale = new Vector3(50f, 50f, 50f);
    6.         box.layer = box.transform.parent.gameObject.layer;
    7.         box.GetComponent<Renderer>().enabled = false;
    8.         box.AddComponent<BoundBox>();
    9.     }
    What could be wrong?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    "Doesn't actually work" in what sense? Bounding boxes don't actually do anything.
     
  3. codenamed52

    codenamed52

    Joined:
    Apr 2, 2019
    Posts:
    4
    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.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I have many questions, but let's start with
    1. What is this "DrawLines" component you're talking about?
    2. What is BoundBox, for that matter? (Neither of these is a standard Unity component.)
    3. 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...
     
  5. codenamed52

    codenamed52

    Joined:
    Apr 2, 2019
    Posts:
    4
    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.

    scr1.png

    scr2.png