My scene is stuck in the is loading stage while also using power

No matter whether I load the scene from the main menu scene or directly in the scene editor in the unity project, it doesn’t load and is just causing the project to not respond while also using up power from the computer.

Edit: When building and testing the program, it crashes as soon as it loads the main scene. I have a lot of loops (because its a clicker game) but this suddenly started randomly over Easter and I’ve tried to use as many of these loops in unity Update() functions.

Edit 2: I’ve managed to track the issues to my save system when it saves the game crashes, here are the two scripts for it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class SaveData
{
    public float coins;
    public float coinsPerSecond;
    public float coinsToAdd;

    public int[] buildings;
    public float[] buildingCPS;

    public bool[] upgrades;

    public float currentTimeHour;
    public float currentTimeMinute;
    public float currentTimeSecond;

    public SaveData (ClickerController controller, BuildingPanelController buildingPanel, UpgradesPanelController upgradePanel)
    {
        coins = controller.coins;
        coinsPerSecond = controller.coinsPerSecond;
        coinsToAdd = controller.coinsToAdd;

        buildings = new int[buildingPanel.controller.Count];
        for(int i = 0; i < buildings.Length; i++)
        {
            buildings _= buildingPanel.controller*.amount;*_

}

buildingCPS = new float[buildingPanel.controller.Count];
for(int i = 0; i < buildingCPS.Length; i++)
{
buildingCPS = buildingPanel.controller*.coinsPerSecond;*
}

upgrades = new bool[upgradePanel.controller.Count];
for(int i = 0; i < upgrades.Length; i++)
{
upgrades = upgradePanel.controller*.effectActive;*
}

currentTimeHour = System.DateTime.Now.Hour;
currentTimeMinute = System.DateTime.Now.Minute;
currentTimeSecond = System.DateTime.Now.Second;
}
}

And the other one:
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;

public static class SaveSystem
{
public static void SaveGame(ClickerController controller, BuildingPanelController buildingPanel, UpgradesPanelController upgradePanel)
{
BinaryFormatter formatter = new BinaryFormatter();

string path = “D:/CryptoClicker/SaveData/playdata.sav”;

if(File.Exists(path))
{
FileStream stream = new FileStream(path, FileMode.Create);

SaveData data = new SaveData(controller, buildingPanel, upgradePanel);

formatter.Serialize(stream, data);
stream.Close();

Debug.Log("Game Saved at " + path);
}
else
{
Debug.Log(“Creating path.”);

string directoryPath = “D:/CryptoClicker/SaveData/”;
Directory.CreateDirectory(directoryPath);

Debug.Log("Created save game at " + directoryPath);

SaveGame(controller, buildingPanel, upgradePanel);
}
}

public static SaveData LoadGame()
{
string path = “D:/CryptoClicker/SaveData/playdata.sav”;

if(File.Exists(path))
{
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(path, FileMode.Open);

SaveData data = formatter.Deserialize(stream) as SaveData;
stream.Close();

Debug.Log("Loaded Game from " + path);

return data;
}
else
{
Debug.Log("Save file does not exist in " + path);
return null;
}
}
}

The path is not an issue and is set that way for getting around school computer restrictions (will be changed later to be more accessable).

looks like an infinite loop or something. start removing scripts from scene or comment parts of scripts till you get it working again then you should figure out the part that creates issues

In the block here in your SaveSystem.SaveGame method:

         else
         {
             Debug.Log("Creating path.");
 
             string directoryPath = "D:/CryptoClicker/SaveData/";
             Directory.CreateDirectory(directoryPath);
 
             Debug.Log("Created save game at " + directoryPath);
 
             // This line causes issues potentially
             SaveGame(controller, buildingPanel, upgradePanel);
         }

You are calling the same function again, which checks if a file exists at a path, but you never create a file, only the directory. This will infinitely loop and inevitably crash, since it isn’t called in an Update loop. Here’s how you would fix it:


             else
             {
                 Debug.Log("Creating path.");

                // Will actually create a file at the desired directory
                File.Create(path).Close();
     
                 Debug.Log("Created save game at " + path);
     
                 SaveGame(controller, buildingPanel, upgradePanel);
             }

I see that that’s the only issue that might be causing your scripts to crash. Hope that fixes it @Artemis123