Quantcast
Channel: Questions in topic: "dontdestroyonload"
Viewing latest article 21
Browse Latest Browse All 416

Data held in Don'tDestroyOnLoad disappearing on scene change

$
0
0
Hey guys, So I have a game manager script that uses the DontDestroyOnLoad function to stay persistent across scene changes. The game manager holds an instance of a custom class called ShipInfo.cs, which has an array of scriptable objects. In the first scene, a spaceship receives upgrades, which are recorded in this scriptable object array. When the new scene loads, the spaceship is built at runtime, and the upgraded items are added to the ship, using the array of scriptable objects as a guide. Initially, this was working as intended, but now it doesn't seem to be holding the new information when the scene change occurs. There are a few items in this array that are manually declared in the Inspector, and they remain in there, but any others that are added to it during the upgrade scene disappear when the scene changes. Here is the ShipInfo script using System.Collections; using System.Collections.Generic; using UnityEngine; [System.Serializable] public class ShipInfo { public ShipClassSO shipClassSO; public ShipComponent[] shipComponents; // this is the array of scriptable objects mentioned above } I've made quite a few changes before I noticed this was happening, so I have no idea what I did that caused it. But the array has the added items before I click the button to go to the next scene (and all that does is load the next scene, nothing else), and afterward, those items I added are gone. I've been troubleshooting this for a while and I just want to get some fresh eyes on it to see what I'm missing. Thanks in advance!

Viewing latest article 21
Browse Latest Browse All 416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>