Hi there!
I'm sorry to ask such an open ended question but I'm kinda clueless again about the wonders of C# programming with Unity and I could use some help: I'll be as specific as possible.
I've got a script with DontDestroyOnLoad() and Serializable that instantiates a Class which inherits from : ScriptableObject and caches the new instance inside a list.
That class has some public variables and is Serializable, so everything should be memorised.
So far so good I'd dare to say.
**But** *when it comes to re-call the instance of that class cached in the list, ***not all of its variables' values are returned correctly**
To be more specific, that instance has many lists with items inside, one of them returns properly while another one keeps track of its .Count but not of its items, that are turned into null.
For what's worth, I'm posting the chunks of codes interested!
This is the first class, a sort of Game Controller or Master, whatever... it's inside every scene of the game attached to an empty Game Object ( it's a singleton):
[System.Serializable]
public class GameMaster : MonoBehaviour {
public static List matrices = new List(); //Stores all matrices generated in game
void Awake () {
if(matrices.Exists(x=>x.associatedLevel == Application.loadedLevel)){
//Recall the scene
matrices[Application.loadedLevel].RecallScene();
}
else{
//Build the Matrix and cache its instance in matrices...
}
}
}
Here's the other script, it's the MatrixMaster class, of which the grid-matrix returns properly, while the propsCached list doesn't:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
[Serializable]
public class MatrixMaster : ScriptableObject {
public List propsCached = new List();//Stores all Objects spawned, except for those already in scene
///
/// Initializes a new instance of the class. Empty Constructor == Cool Cat Class
///
public MatrixMaster(){
//I am empty: initialize me!
}
public void RecallScene (){
//Load cached list - I've populated it when I first initialised this instance
foreach(GameObject go in propsCached){
//Instantiate
GameObject clone = Instantiate(go);
//HERE THE OBJECTS BECOME NULL
}
}
}
I know it's a pain in the butt to look through many lines of code, but if you managed to get so far I thank you for your attention!
↧