title: Error on setting a Pooled GameObject's parent back to pooled container
body: <p>I have a GameObject that I am spawning from a pool, that when I try to return it to the pool I get the error:</p>
  
  <blockquote>
    <p>Setting the parent of a transform which resides in a prefab is
    disabled to prevent data corruption.</p>
  </blockquote>
  
  <p>I have used my ObjectPooler in many projects and have never once encountered this error.</p>
  
  <p>I have created simple test GameObjects and it still throws this error, using the below code.</p>
  
  <p>I have a <code>Bomb</code> abstract class. I have a <code>PowerBomb</code> class that inherits from <code>Bomb</code>. <code>Bomb</code> conforms to an interface <code>IExplodable</code>.</p>
  
  <p>When my player spawns a bomb, I put it as the child of the player object so the player can move around with the bomb. </p>
  
  <p>My ObjectPool has the correct bomb gameobject prefab ( a PowerBomb ). and my player has the same prefab as a reference to spawn. They player also holds a reference so it knows what it is holding.</p>
  
  <p>I have spent the better part of 2 days trying to figure out why my PowerBomb will not return to the object pool.</p>
  
  <p><em>Any help?</em></p>
  
  <p><strong>Bomb.cs</strong></p>
  
  <pre><code>public abstract class Bomb : MonoBehaviour, IExplodable {
  
      //Interface
      public virtual void OnDetonate() {
          Die();
      }
  
      public virtual void Die() {
          Debug.Log("Bomb Die()");
          ObjectPool.instance.PoolObject(gameObject);
      }
  }
  </code></pre>
  
  <p><strong>PowerBomb.cs</strong></p>
  
  <pre><code>public class PowerBomb : Bomb {
      [SerializeField]
      private AudioClip sfxSpawn;
  }
  </code></pre>
  
  <p><strong>BombManager.cs</strong></p>
  
  <pre><code>public GameObject bomb;
  
  public void SpawnBomb(){
      GameObject obj = ObjectPool.instance.GetObject(bomb);
      if (obj == null) return;
      obj.SetActive(true);
      PlayerInstance.HoldObject(obj);
  }
  
  
  public void DetonateBomb(){
      bomb.GetComponent&lt;PowerBomb&gt;().OnDetonate();
  }
  </code></pre>
  
  <p><strong>Player.cs</strong></p>
  
  <pre><code>[SerializeField]
  private bool isHolding = false;
  public bool IsHolding {
      get { return isHolding; }
      set { isHolding = value; }
  }
  
  private GameObject holdingObject;
  public GameObject HoldingObject {
      get { return holdingObject; }
      set { holdingObject = value;}
  }
  
  public void HoldObject(GameObject o) {
      HoldingObject = o;
      HoldingObject.transform.SetParent(transform);
      HoldingObject.transform.position = holdingArea.transform.position;
      IsHolding = true;
  }
  </code></pre>
  
  <p><strong>ObjectPool.cs</strong></p>
  
  <pre><code>private GameObject containerObject;
  private List&lt;GameObject&gt;[] pooledObjects;
  
  
  //Code removed for brevity. Getting from the pool is fine.    
  
  
  public void PoolObject(GameObject obj) {
      for (int i = 0; i &lt; objectsToPool.Count; i++) {
          if (objectsToPool[i].objectToPool.name.Equals(obj.name)) {
              obj.SetActive(false);
  
  //THIS LINE IS THROWING THE ERROR
              obj.transform.SetParent(containerObject.transform); 
  
              pooledObjects[i].Add(obj);
              return;
          }
      }
  }
  </code></pre>