S
S
Suren2018-05-15 12:09:18
C++ / C#
Suren, 2018-05-15 12:09:18

How to move an Array from one scene to another?

We need to transfer the Array of GameObjects from one scene to another.
I tried to do it through DontDestroyOnLoad, but in another scene, the objects disappear from the array.
Is there a way to do this without using Json type persistence methods, etc. ?
Or just by saving in one scene and parsing in another?

public GameObject myCollectionCard;    
    public GameObject[] myPullCard;

    private void Awake()
    {
        myPullCard = new GameObject[myCollectionCard.transform.childCount];
        DontDestroyOnLoad(gameObject);
    }

    public void GetMyPullCard()
    {
        for (int i = 0; i < myPullCard.Length; i++)
        {
            myPullCard[i] = myCollectionCard.transform.GetChild(i).gameObject;
        }   
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2018-05-15
Jagaryan @saylar

Put all objects as children in one rootObject. You make this rootObject DontDestroyOnLoad. You hang a script on it, into the array of which you drive all the necessary objects.
After loading the scene, both the array is intact and the objects.

F
freeExec, 2018-05-15
@freeExec

An array with objects is also stored in an object with the DontDestroyOnLoad flag.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question