I have never seen a null reference exception like this one!

I have a null reference exception and this is the exact error : NullReferenceException: Object reference not set to an instance of an object
(wrapper stelemref) object:stelemref (object,intptr,object)
PlacingParts.Update () (at Assets/Scripts/BuildingRocket/PlacingParts.cs:39). I have a feeling it’s the reason my snapping script isn’t working ,but I don’t know. Here is the script:

using UnityEngine;
using System.Collections;

public class PlacingParts : MonoBehaviour 
{
	public GameObject[] placedParts;
	private int i;
	private Transform currentPart;
	public Transform centerPoint;

	private int partLayerMask = 1 << 9;
	private int snapPointLayer = 1 << 8;

	private bool hasPlaced;
	public float snapPointDistance = 5f;

	void Start () 
	{
		i = 0;
		hasPlaced = false;
	}
	void Update ()
	{
		//HOW TO PLACE THE ITEM
		if (currentPart != null && hasPlaced == false)
		{
			//GIVES ME THE ABILITY TO MOVE THE PART/OBJECT THAT WAS JUST INSTANTIATED WITH THE PLACEITEM FUNCTION
			Vector3 m =  Camera.main.ScreenToWorldPoint (new Vector3(Input.mousePosition.x, Input.mousePosition.y, 12.9f +( MouseOrbitImproved.distance - 13.5f)));
			currentPart.position = new Vector3(m.x,m.y,m.z);

			//SET THE ITEM TO HAS PLACED SO THAT IT STOPS MOVING
			if(Input.GetMouseButtonDown (0))
			{
					placedParts *= currentPart.gameObject;*
  •  			hasPlaced = true;*
    
  •  			i++;*
    
  •  	}*
    
  •  }*
    
  •  //HOW TO PICK THE OBJECT BACK UP AFTER IT HAS BEEN PLACED*
    
  •  Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);*
    
  •  RaycastHit hit;*
    
  •  if(Physics.Raycast (ray, out hit, Mathf.Infinity, partLayerMask))*
    
  •  {*
    
  •  }* 
    
  •  if(placedParts != null && i < placedParts.Length)* 
    
  •  {*
    

_ SnapTry(currentPart, placedParts*.transform);_
_
}_
_
}_
_
void SnapTry(Transform obj1, Transform obj2) {_
_
//WHEN CALLING THE SCRIPT OBJ1 MUST BE THE CURRENTPART*_
* Transform[] transforms1 = obj1.GetComponentsInChildren();*
* //OBJ2 HAS TO BE AN ARRAY FILLED WITH ALL THE PLACED OBJECTS TRANSFORMS*
* Transform[] transforms2 = obj2.GetComponentsInChildren();*

* foreach(Transform tr1 in transforms1) {*
* foreach(Transform tr2 in transforms2) {*

* if (tr1.tag == “SnapPoint” && tr2.tag == “SnapPoint” && (tr1.position - tr2.position).sqrMagnitude <= snapPointDistance) {*
* Debug.Log (“You could snap an object here if the script was finsihed”);*
* }*
* }*
* }*
* }*

* public void PlaceItem(GameObject b)*
* {*
* hasPlaced = false;*
* currentPart = (((GameObject)Instantiate(b)).transform);*
* }*
}

You declare the ‘placedParts’ variabled, but you never initialize it. That is you have a reference to an array, but you also need to declare a specific amount of space for that array. Something like:

public static GameObject[] placedParts = new GameObject[100];

That creates 100 slots in your array. If you don’t know how big the array will be, you can move to a different collection type. Usually a generic List is a good choice for a variable size array. More info on collection types:

http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use%3F