# C# new BoxCollider() returns null?

**URL:** https://discussions.unity.com/t/c-new-boxcollider-returns-null/17293
**Category:** Questions & Answers
**Created:** [March 22, 2011, 4:24pm UTC](https://discussions.unity.com/t/c-new-boxcollider-returns-null/17293 "2011-03-22T16:24:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/system/32/97283_2.png) [@system](https://discussions.unity.com/u/system)
#### Post date: [March 22, 2011, 4:24pm UTC](https://discussions.unity.com/t/c-new-boxcollider-returns-null/17293/1 "2011-03-22T16:24:57Z")

</div>

I am trying to create a new temporary box collider at a raycasts hit location on click however cannot seem to make a new box collider in script to do so.

```auto
Ray v = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit = new RaycastHit();
            if(Physics.Raycast(v,out hit,100.0f))
            {
                MeshFilter mf = (MeshFilter)hit.collider.gameObject.GetComponent(typeof(MeshFilter));
                if(mf)
                {
                    //create a copy of the mesh to trim
                    Mesh decalMesh = Mesh.Instantiate(mf.mesh) as Mesh;
                    BoxCollider bc = new BoxCollider(); //<--- bc = NULL
                }

```

What am I missing about creating a box collider that I can use to test against a mesh's triangles?

---

<div class="post-metadata">

### Author: ![anon85704231](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@anon85704231](https://discussions.unity.com/u/anon85704231)
#### Post date: [March 22, 2011, 4:28pm UTC](https://discussions.unity.com/t/c-new-boxcollider-returns-null/17293/2 "2011-03-22T16:28:39Z")

</div>

You need to use specificGameObject.AddComponent()

This goes for all components, you're not supposed to use new on them - you can't attach them to anything after
