The Object you want to instantiate is null.

hey, Im having this error what it should do its when the tree gets removed/destroyed it show spawn Logs and coconuts near the tree i have those prefabs in a folder.

When i Chop down a Tree, when it get removed it should appear logs and coconuts but it dont and it does this error

private void Start()
{
    thisTree = transform.parent.gameObject;
}

private void Update()
{
    if(treeHealth <= 0 && isFallen == false)
    {
        Rigidbody rb = thisTree.AddComponent<Rigidbody>();
        rb.isKinematic = false;
        rb.useGravity = true;
        rb.AddForce(Vector3.forward, ForceMode.Impulse);
        StartCoroutine(destroyTree());
        isFallen = true;
    }
}

private IEnumerator destroyTree()
{
    yield return new WaitForSeconds(5);
    Destroy(thisTree);

	Vector3 position = new Vector3(Random.Range(-1.0f, 1.0f), 0, Random.Range(-1.0f, 1.0f));
	Instantiate(Log, thisTree.transform.position + new Vector3(0,0,0) + position, Quaternion.identity);
	Instantiate(Log, thisTree.transform.position + new Vector3(2,2,0) + position, Quaternion.identity);
	Instantiate(Log, thisTree.transform.position + new Vector3(5,5,0) + position, Quaternion.identity);

	Instantiate(Coconut, thisTree.transform.position + new Vector3(0,0,0) + position, Quaternion.identity);
	Instantiate(Coconut, thisTree.transform.position + new Vector3(2,2,0) + position, Quaternion.identity);
	Instantiate(Coconut, thisTree.transform.position + new Vector3(5,5,0) + position, Quaternion.identity);
}

}

Thank you :smiley:

You are calling the destroy function of “thisTree”, and then later referencing its position when you are trying to spawn the logs and coconuts. The solution would be to copy its transform to a local variable, and then reference that variable when you want to spawn the logs and coconuts.