Unity is giving me the following error: NullReferenceException: Object reference not set to an instance of an object SupplyCrash.Update () (at Assets/SupplyDrop/Supply/SupplyCrash.cs:18) I know the issue is with the "smokeClone.transform.position = droppedSupply.transform.position;" part of the code (or I believe it is), but I have no idea how to correct it. Though the error is coming up, everything works as expected when I test the game. Here is the exact code I am using: Code (CSharp): public GameObject crashSmoke; public GameObject droppedSupply; GameObject smokeClone; bool hasCollided = false; private void Update() { smokeClone.transform.position = droppedSupply.transform.position; } private void OnCollisionEnter(Collision collision) { if (!hasCollided) { smokeClone = Instantiate(crashSmoke, transform.position, transform.rotation); hasCollided = true; } }
"smokeClone" is assigned in the OnCollisionEnter() function but you are trying to reference it every frame in the Update() function. Consider checking whether it's null first: Code (CSharp): void Update() { if(smokeClone != null) { smokeClone.transform.position = droppedSupply.transform.position; } }