Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

Copy a 2D array of GameObjects

$
0
0
How do you make a copy of a 2D array of GameObjects (made from instantiated prefabs) in another script. The array I want to copy is pieces[8,8] in GameManager.cs. I have tried: for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (GameManager.instance.pieces [i, j] != null) { GameObject temp = new GameObject(); pieces[i,j] = GameManager.instance.pieces[i, j]; } } } and private GameObject[,] pieces pieces = new GameObject[8,8]; pieces = GameManager.instance.pieces.Clone(); and many, many other ideas... The issue is a NullReferenceException anytime one of the "copied" GameObjects is used in any method. Thanks in advance.

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>