2017-01-17 9 views
0

私のオブジェクトであるプレハブを変更したいplayerPawnが関連付けられています。私はこのコードでそれを実行しようとしました:ユニファイドでプレハブのオブジェクトが関連付けられている

int i = 0; 

PrefabUtility.DisconnectPrefabInstance(this.playerPawn); 
PrefabUtility.ConnectGameObjectToPrefab (this.playerPawn, this.playerPawnPrefabs [i]); 

Debug.Log(this.playerPawnPrefabs[i]); 

PrefabUtility.ResetToPrefabState(this.playerPawn); 

はしかし、最後の行は、このエラーがスローされます。

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.

Debug.Log()は、this.playerPawnPrefabs[i]は私が期待していゲームオブジェクトが含まれていることを見せてくれたIドンそうそのエラーがどこから来るのか理解できません。

+0

ゲームオブジェクトが破壊されていると表示されます。 debug.logを試してみてください:すべてのPrefabUtility-usageの間にthis.playerPawnを入れますか? – Maakep

+0

'Debug.Log(this.playerPawn) 'を使うと、' ConnectGameObjectToPrefab 'の呼び出しの後にゲームオブジェクトが破壊されたことがわかります。 –

+0

'this.playerPawnPrefabs [i]'がヌルではありませんか? – Programmer

答えて

1

たぶん、あなたはあなたのplayerPawnオブジェクトにConnectGameObjectToPrefabメソッドの戻り値を再割り当てしようとすることができます:

this.playerPawn = PrefabUtility.ConnectGameObjectToPrefab (this.playerPawn, this.playerPawnPrefabs [i]); 

次にあなたがResetToPrefabStateメソッドを呼び出すことができます。

関連する問題