MissingReferenceException at scene unload time
I want to store my data when current running scene was unloaded. For this purpose I have written following code:
void OnDisable ()
{
BackUpPuzzleData();
}
public void BackUpPuzzleData ()
{
if (DataStorage.RetrievePuzzleStatus (difficultyLevel, puzzleId) == Constants.PUZZLE_NOT_OPENED
&& DataStorage.RetrievePuzzleStatus (difficultyLevel, puzzleId) != Constants.PUZZLE_COMPLETED)
DataStorage.StorePuzzleStatus (difficultyLevel, puzzleId, Constants.PUZZLE_RUNNING);
if (DataStorage.RetrievePuzzleStatus (difficultyLevel, puzzleId) == Constants.PUZZLE_RUNNING)
StorePuzzleData ();
}
private void StorePuzzleData ()
{
DataStorage.StorePuzzleTimePassed (difficultyLevel, puzzleId, GameController.gamePlayTime);
foreach (Transform cell in gridTransform) {
CellInformation cellInfo = cell.GetComponent<CellInformation> ();
if (cellInfo != null) {
CellStorage.StorePuzzleCellNumber (difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.number);
CellStorage.StorePuzzleCellColor (difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.CellColor);
CellStorage.StorePuzzleCellDisplayColor (difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.CellDisplayColor);
}
}
}
But when OnDisable method gets called at that time Console giving me following error:
I have already set execution order of scrip in project settings then why I am getting this kind of error?
EDIT: Basically I want to save current game play data so when game player return back he can again start from which he left game.
Answer by siddharth3322 · May 01, 2016 at 06:41 AM
Passing some time with this problem, now I can able to figure out this problem. I don't know how much solution was correct but at least now working for me.
Here I am discussing this because some members get some hint from this.
At game load time, I filled up one list with all cell's script. Each cell of grid has one script attached CellInformation. So I prepare list of all these cells script.
At game disable time, I fetched value from these scripts and store into local storage. I can able to access scripts but not game objects from list because they were already destroyed.
void OnDisable ()
{
StorePuzzleData ();
}
private void StorePuzzleData ()
{
DataStorage.StorePuzzleTimePassed (difficultyLevel, puzzleId, GameController.gamePlayTime);
foreach (CellInformation cellInfo in cellInfoList) {
CellStorage.StorePuzzleCellNumber (difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.number);
CellStorage.StorePuzzleCellColor (difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.CellColor);
CellStorage.StorePuzzleCellDisplayColor (difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.CellDisplayColor);
CellStorage.StorePuzzleCellGroupComplete (difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.IsGroupComplete ? 1 : 0);
}
}
I hope this will give some hints to other programmers.
Answer by rober-psious · Apr 27, 2016 at 01:42 PM
You can try with this:
private void StorePuzzleData ()
{
DataStorage.StorePuzzleTimePassed(difficultyLevel, puzzleId, GameController.gamePlayTime);
for (int i = 0; i < gridTransform.Length; i++)
{
Transform cell = gridTransform[i];
if (cell != null)
{
CellInformation cellInfo = cell.GetComponent<CellInformation>();
if (cellInfo != null)
{
CellStorage.StorePuzzleCellNumber(difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.number);
CellStorage.StorePuzzleCellColor(difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.CellColor);
CellStorage.StorePuzzleCellDisplayColor(difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.CellDisplayColor);
}
}
}
}
@rober.psious, I understand what you are trying to say. But I want to store all cells data. Because when game player come back at that time I want to load it back.
Do you have any other solution?