2016-10-10 39 views
0

當我嘗試設置父爲實例化對象,我得到這個錯誤:與對象設置父問題

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

我搜索谷歌因爲同樣的錯誤,它似乎不是成爲問題在我的情況。

代碼:

[SerializeField] GameObject scoreboardItem; 
[SerializeField] Transform playerList; 

GameObject itemGO = (GameObject) Instantiate(scoreboardItem); 
itemGO.transform.SetParent(playerList); 

解決什麼解決?

+0

確保playerList變換拖放到檢查器來自「Hierarchy」面板而不是「Project」面板。 – Hellium

+0

如果我這樣做了,那麼我就不能使用預製件。我也試圖通過GameObject.FindGameObjectWithTag()找到playerList,但是同樣的錯誤。 –

回答

0

不知何故我需要做在啓動方法下面內部相同的方法,而不是:

GameObject scoreList = GameObject.FindWithTag("ScoreboardContent"); 
0

Playerlist必須是一個對象引用。但事實並非如此,它只是數據。