Scriptable Objects Crash Editor on Load

I’ve been having a ton of trouble with SOs since I’ve been learning them. At first my editor kept crashing because I was using them with TextMeshPro, so I switched to Unity text, and now something new.

First, I will say that everything is working as intended. My code does exactly what I want it to. I can see the inspector updating to what I want during runtime, but when I exit runtime, the editor crashes.


This is the project I made to teach myself SOs. The panel on the left is what you have equipped. The middle panel is your inventory, and the right panel shows your stats gained from the equipped items and where each stat is getting its’ data from.

This is how I check what you have equipped:


You can see the scriptable objects at the top, and the health/damage text that I need to change according to what is equipped. The “white” gear is default gear which basically means nothing is equipped so it gives 0 health and damage.

If you go back to the first picture of the game view, you will see that the first thing in the inventory is a blue helmet and that is what I am working on first. I put a button on that helmet and have it execute this code:

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

public class ButtonEquip : MonoBehaviour
{
    public Equip eq;

    public void BlueHelmet()
    {
        eq.helmet = Resources.Load<Inv>("Equips/Blue/Helmet_Blue");
    }
}

And now I will show the script that this script is referencing:

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

public class Equip : MonoBehaviour
{
    public Inv helmet;
    public Inv chestplate;
    public Inv leggings;
    public Inv boots;
    public Inv sword;
    public Inv ring;

    public Text healthOverall;
    public Text damageOverall;

    public Text helmHealth;
    public Text chestplaHealth;
    public Text legginHealth;
    public Text booHealth;
    public Text swoHealth;
    public Text riHealth;

    public Text helmDamage;
    public Text chestplaDamage;
    public Text legginDamage;
    public Text booDamage;
    public Text swoDamage;
    public Text riDamage;

    void Start()
    {
        healthOverall.text = (helmet.health + chestplate.health + leggings.health + boots.health + sword.health + ring.health).ToString();
        damageOverall.text = (helmet.damage + chestplate.damage + leggings.damage + boots.damage + sword.damage + ring.damage).ToString();

        helmHealth.text = helmet.health.ToString();
        helmDamage.text = helmet.damage.ToString();
        chestplaHealth.text = chestplate.health.ToString();
        chestplaDamage.text = chestplate.damage.ToString();
        legginHealth.text = leggings.health.ToString();
        legginDamage.text = leggings.damage.ToString();
        booHealth.text = boots.health.ToString();
        booDamage.text = boots.damage.ToString();
        swoHealth.text = sword.health.ToString();
        swoDamage.text = sword.damage.ToString();
        riHealth.text = ring.health.ToString();
        riDamage.text = ring.damage.ToString();
    }
}

As expected, when I click the blue helmet, my equipped helmet changes from white to blue and the text doesn’t update because nothing has told it to yet. But when I exit the play mode, the editor crashes. I would appreciate any help, please let me know if you need any further details.

First of all, love the diagrammatic view of helm, chest, leggings and boots, then weapon and ring… very nicely done.

As for the code you posted above, I don’t see any loops or other weirdness.

When you say crash does it just freeze or does it drop to the desktop?

Also, check your device and / or editor logs; google for how on your target operating system.

You could also just try reimport all, see if perhaps one asset was corrupt somehow.

Oh yeah, I do see one minor typo… Sword is mentioned twice under Health while Ring is not mentioned at all under Health.

1 Like

Was gonna say the same as Kurt, I don’t think the crashing (depending on what exact kind of crash it is) is related to your code at all. At least not the code we can see.

Check the editor.log in any case. You can find info on where they are here: Unity - Manual: Log files

What Unity version are you on?

1 Like

Thank you so much for the quick reply. Okay so I reimported all just to see if that was a quick fix and it still crashed. What I mean by “crash” is that this happens as soon as I click to stop playing:
9770805--1400154--upload_2024-4-14_22-38-46.png
I copied my crash log (not my normal editor log) over to a text document so I was able to attach it here. There’s a whole lot in there I’m not understanding but hope it will prove a little useful lol.

9770805–1400157–crash.txt (654 KB)

Honestly was thinking it was something weird. When my project was crashing before, it was from the TextMeshPro package in my Unity project. Even after disabling everything in my project, it would still crash. So I really think it is something weird like last time but I have nothing else installed other than basic Unity stuff. This project is in 2023.2.2f1

First thing I would try is updating to the latest 2023.2 version. That’s an early version so it’s not unusual for there to be these kinds of instabilities. I’ve been using the latest 2023.2 versions without too much hassle.

1 Like

Yup, that was it! Thank you for the help. Doesn’t exactly explain what happening but I don’t care enough to find out. Before I updated, I confirmed that the editor does crash even without anything being enabled in the inspector so I knew that my entire project was messed up again. After I updated it seems to be gone, but hopefully it doesn’t come back like last time, but I have faith. Still have PTSD every time I hit stop play lol.

3 Likes