Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 vptb · Sep 18, 2014 at 11:01 AM · objectscene-loadingstaticcompare

Static variable to check objects between scene reloads

Basically I have some items on the game which the player can pick up. When those items are picked they disappear. I also want it so that if the player dies, when the scene is reloaded, those items that he already picked up, won't spawn again.

Standard procedure was to create a static List, which I add a picked object, and when the scene reloads the List will keep the information.

My problem:

1st run - player picks up Object A. Object A is added to the list.

2nd run - when the scene starts the Object A checks if the list already contains himself, but it always returns false.

Basically Object A in Scene X on run 1, is different from Object A in Scene X on run 2. Is there any way that I can relate those two objects?

I tried with gameObject, with a MonoBehavior, with GetInstanceId(), but none of those worked.

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

Answer by HarshadK · Sep 18, 2014 at 11:24 AM

You can assign a unique ID to all your pickup objects in a script that you can write and attach to all your pickup objects. It is just a variable that you assign to your each game object with its value as the ID for that object. Be sure to provide each instance of an object a unique ID so that no two instances of same type of object has the same ID (in case required). Now when the object is serialized this ID will be serialized as the ID of that object.

Now when the object is picked up you can store that ID in your static list. Whenever the scene loads again you can check if that ID is present in the list. Since these IDs are unique and are stored in the object itself in your script.

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 vptb · Sep 18, 2014 at 11:28 AM 0
Share

Yeah, but I really didn't want to do that because there's a lot of items and a lot of levels. I wanted something that wouldn't require manual work.

avatar image HarshadK · Sep 18, 2014 at 01:41 PM 0
Share

You can create an editor script to generate and assign these IDs to game objects for you.

avatar image
0

Answer by VamshiKrishnaP · Sep 18, 2014 at 11:58 AM

when you are playing 2nd time, values never reset until application quit. Don't assign any values to static variables in start() / awake() . just declare the static variables.

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 vptb · Sep 18, 2014 at 01:26 PM 0
Share

You totally missed my question.

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

23 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

Related Questions

object.ToString never equals the string 2 Answers

An object reference is required to access non-static member `UnityEngine.Component.transform' 1 Answer

Object rotation from web page values 1 Answer

Do you have to set a object reference for every script? 0 Answers

Enable/Disable a Static object 1 Answer


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