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 /
avatar image
0
Question by lewisallanreed · Oct 04, 2015 at 06:17 PM · staticlistsscenesglobalchanging

How to make a list store and save values even while changing scenes.

Skip directly to the question if you want

INTRODUCTION->

Hi everyone, gonna start with a couple of details first: my game is based around a TABS mechanic, by which I mean that the game is managed by the player in every aspect thanks to different windows, which he can access by clicking on different little buttons on top of the gameview (map, objectives, inventory). Each TAB is actually a different game scene. That, as you can probably guess, requires a lot static variables, which I've used so far quite efficently, allowing me to create seamless transitions between the sections (TABS), which are thus constantly updated. Consequently, thanks to this system, the typical scenario sees the player picking up an object in the ACTIVE TAB/scene and, if he moves to the INVENTORY TAB/scene, finding it in the inventory already.

THE PROBLEM->

The problem is that I've implemented the inventory system using Lists, of which I know very little. Basically, my inventory List (called itemList) contains lots of items of the custom class Item(string to show the name of the object, Sprite to represent it in the scroll-list, int to display the quantity). Everything works fine, in theory, because, as I populate the list adding items (through the inspector or via script), they do show up in the inventory scroll-list in the game (and in the inspector, for that matter). The problem comes when I move to any other TAB (say the MAP TAB, for example) and come back: the list presents only the one item I've put into it manually, via the inspector, as a test. It is basically restored from any addition (or subtraction, for that matter) achieved through scripting at runtime. I've tried using something like public static List but to no effect. I keep getting error messages like:

  • "Static member `CreateScrollList.itemList' cannot be accessed with an instance reference, qualify it with a type name instead" or

  • "Object reference not set to an instance of an object"

THE QUESTION->

Is there a way to make the List "static-like", so that it can store changes to its contents even when changing scene?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by meat5000 · Oct 04, 2015 at 06:18 PM

I would say that in this case you may need an additive loading approach.

http://docs.unity3d.com/ScriptReference/Application.LoadLevelAsync.html

This way you can load and unload scenes into a currently existing scene.

Comment
Add comment · Show 2 · 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 lewisallanreed · Oct 04, 2015 at 06:35 PM 0
Share

Interesting, didn't even know such a thing existed! So what you'd be suggesting is for me to basically open the inventory as the base/root scene and then open all the other windows later, with this asynchronous method, thus not requiring for the list to save the values inbetween scenes, as technically I'd never be leaving the inventory scene (which would otherwise reset the list). Very clever! Thank you!! But wouldn't it be possible to do what I had intended at the very start? Is it something that Lists allow? (Oh, to store values inbetween scenes, that is...)

  • edit *

come to think of it double thank you as well, because I might be using this to enable the player to walk into different rooms in the same building during the active game without them resetting every time!!

avatar image meat5000 ♦ lewisallanreed · Oct 04, 2015 at 06:38 PM 1
Share

I suggest this approach as it will allow you to keep using your List WHILST loading another scene.

Other approaches would include DontDestroyOnLoad or making static objects, both of which will retain objects, but I'm not sure if it retains data. Of course, during a scene change you get a hard load. Not a good approach for a seamless tabs system.

Give thanks with an upvote ;) If you try the method an it works, click the tick to accept the answer.

And, you are most welcome.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Is there any way to edit variables inside other scripts without declaring them as static? 1 Answer

Prefab's Script affecting all the Prefab 1 Answer

How can I preserve static object/data between editor and play? 2 Answers

Creating a list using a list from another script? 1 Answer

Instantiating a Coroutine? 2 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