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.

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.

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.