I have a script that uses a bunch of lists to store lists of ScritableObjects:
private List<VehiclePartData> _changedAdjusts = new();
private List<VehiclePartData> _selectedParts = new();
private List<VehiclePartData> _partsToInstall = new();
private List<VehiclePartData> _partsToUnninstall = new();
when I want to add an item to one list, varying on the logic of what list to use, it will be like this:
if (!_selectedParts.Contains(part))
{
_selectedParts.Add(part);
Debug.Log($"Selecting part
{part.LocalizedName.GetLocalizedString() ?? part.Name}");
}
The object that holds these lists is part of a scene that’s loaded additively and then unloaded when player exits, so the object is disabled together. On the first time that this scene is loaded, the code above works as expected, and the part is added to the list:
But when we exit the scene and enter again, the debug.log shows but the part is no longer added to the list:
I tried many things like clearing or initializing the list on Start and OnEnable but nothing fixes this, and I have no other clue of the reason for this to be happening.