I have run into a strange issue working with arrays.
I have two scripts. Script A is attached to a PREFAB that is not in the scene until runtime.
Script A simply has an array of gameobjects called playerDeck.
I use the inspector and set the array to 30.
I then populate it with PREFABS until all 30 slots are filled.
Script A:
public GameObject[] playerDeck;
Moving onto script B. I have this script attached to a different gameobject that
is there from the start and is NOT created on runtime.
Same deal, an array of prefabs set to 30 in the inspector but left all empty.
I also have a gameobject set to have an instance of the player’s prefab
I fill the playerPrefab slot in the inspector by using the PREFAB named “player”
This “player” has a script called playerScript.cs(Script A in this case)
I then call the line where I want to copy the deck, but nothing seems to copy over.
The array for the second object doesn’t copy anything over and is left blank.
Script B:
public GameObject[] masterDeck;
public GameObject playerPrefab;
masterDeck = playerPrefab.GetComponent<playerScript>().playerDeck;
What am I doing wrong here? This is setting me back quite a bit. I suspect the issue is because I am using a prefab…is there any way around this?
EDIT: the object is instantiated. Script A is instantiated at runtime.
I am using PUN(photon unity networking) to instantiated them. So I am not using the standard unity instantiation.
could this be what is cause the problems?