Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

PREFAB TRANSFORM ERROR PLS HELP I AM NEW!!

Discussion in 'Prefabs' started by Lord_breadcrumb, Jun 2, 2020.

  1. Lord_breadcrumb

    Lord_breadcrumb

    Joined:
    Dec 31, 2019
    Posts:
    4

    "Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption"
    ERROR IS IN LINE 21 (FYI MY PREFAB FOR PLAYER AREA IS ALSO CALLED PLAYER AREA)
    *THIS IS A CARD GAME(THIS IS THE DRAW CARD MECHANIC*
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Draw_cards : MonoBehaviour
    6. {
    7.     public GameObject Card1;
    8.     public GameObject Card2;
    9.     public GameObject PlayerArea;
    10.     public GameObject EnemyArea;
    11.     void Start()
    12.     {
    13.        
    14.     }
    15.  
    16.     public void OnClick()
    17.     {
    18.         for(var i=0; i<=5; i++)
    19.         {
    20.             GameObject playerCard = Instantiate(Card1, new Vector3(0, 0, 0), Quaternion.identity);
    21.             playerCard.transform.SetParent(PlayerArea.transform, false);
    22.         }
    23.     }
    24.  
    25. }
    26.  
     
  2. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Probably because PlayerArea is a Prefab asset and not an instance?
     
  3. Lord_breadcrumb

    Lord_breadcrumb

    Joined:
    Dec 31, 2019
    Posts:
    4
    Oh i thought so too, So do you suggest i instantiate it as a game object
     
  4. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Yes, you have to.