Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by siddharth3322 · Apr 27, 2016 at 01:30 PM · unity 5transformscript.sceneondisable

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:

alt text

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.

screen-shot-2016-04-27-at-65600-pm.png (37.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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);
             }
         }
     }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image siddharth3322 · Apr 27, 2016 at 02:47 PM 0
Share

@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?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

73 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why is this code in the script not stopping the rotation of the Gameobject? 0 Answers

Have object fly towards camera 0 Answers

Enable/Disable other gameobject's scripts Unity 5 0 Answers

I can not add an existing script 0 Answers

[Unity 3D] [C#] Do you have problems working with non-English languages ​​(Korean)? 영어가 아닌 언어(한국어)로 작업시 문제가 생기나요? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges