Still trying to access object error, after level reload?

Hi, im getting this error and simply cant work out where the error lies.

It is pointing to a line where im doing a raycast and its telling me that the object type (gameobject) has been destroyed but im still trying to access it.

The gameobject im using in the raycast is simply a gameobject that i reference to at design time in the inspector. Declared like:

public GameObject myGameObj;

The level restarts it all works fine but the error keeps coming in.

This is the line (59):

if (Physics.Raycast(myGameObj.transform.position, -Vector3.up, out terrPick,1000,1 << 8))

Error is:

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
params.FixedUpdate () (at Assets/params.cs:59)

Can I also add that I have other gameobjects that refer to the same myGameobj above and they dont produce the error. I have omitted the script in the inspector and run it and there are no errors thrown on restarting the level.

Hope you can help
Thanks
Andy

Figured it out. Still not sure why it was point to that line.

The issue was I had another script attached to the same object that had a “DoNotDestroy” in it.

Thanks
Andy