[SOLVED] How do I set the parent of an instance of a prefab that was placed into gameworld, not instantiated in a script?

I’m trying to set the parent of a gameobject that I have placed in the world. The gameobject is an instance of a prefab. When I run the code, it throws the error

Setting the parent of a transform
which resides in a prefab is disabled
to prevent data corruption.
UnityEngine.Transform:set_parent(Transform)

This is the code snippit in question. It is inside a script attached to the prefab of the object I’m trying to change the parent of.

...
public GameObject handGrabContainer;
...
public void beingGrabbed(){
    ...
	this.transform.parent = handGrabContainer.transform;
    ...
}

I have searched online for a solution to this error, and there are several threads about it here, here and here for example. However, in all of those examples, the object is being instantiated in the script. Like this

GameObject myThing= Instantiate(thing, Vector3 (0, 0, 0)) as GameObject;
 myThing.transform.parent = transform;

But I have an object that was placed into the gameworld in the Unity editor. How can I access the transform of the actual object, instead of the prefab, if I am not creating the object a script?

EDIT: It seems that problem was actually with the “handGrabContainer” object. I had it linked to the script in the script’s prefab. The error that I was getting was from the handGrabContainer, not the this.transform.

I’d suggest: Put a breakpoint on the bad line. And stop there in Visual Studio debugger.

Hover over the “this” (or add it to Watch window) in VisualStudio. Take a look at it. I bet “this” is not what you think it is.

Just supply the fourth argument for Instantiate, which is the parent. No need for an extra line for this.