Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Resolved Scriptable Objects Crash Editor on Load

Discussion in 'Editor & General Support' started by diego_unity175, Apr 15, 2024.

  1. diego_unity175

    diego_unity175

    Joined:
    Apr 6, 2024
    Posts:
    6
    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.
    upload_2024-4-14_22-3-20.png
    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:
    upload_2024-4-14_22-4-53.png
    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:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ButtonEquip : MonoBehaviour
    6. {
    7.     public Equip eq;
    8.  
    9.     public void BlueHelmet()
    10.     {
    11.         eq.helmet = Resources.Load<Inv>("Equips/Blue/Helmet_Blue");
    12.     }
    13. }
    And now I will show the script that this script is referencing:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Equip : MonoBehaviour
    7. {
    8.     public Inv helmet;
    9.     public Inv chestplate;
    10.     public Inv leggings;
    11.     public Inv boots;
    12.     public Inv sword;
    13.     public Inv ring;
    14.  
    15.     public Text healthOverall;
    16.     public Text damageOverall;
    17.  
    18.     public Text helmHealth;
    19.     public Text chestplaHealth;
    20.     public Text legginHealth;
    21.     public Text booHealth;
    22.     public Text swoHealth;
    23.     public Text riHealth;
    24.  
    25.     public Text helmDamage;
    26.     public Text chestplaDamage;
    27.     public Text legginDamage;
    28.     public Text booDamage;
    29.     public Text swoDamage;
    30.     public Text riDamage;
    31.  
    32.     void Start()
    33.     {
    34.         healthOverall.text = (helmet.health + chestplate.health + leggings.health + boots.health + sword.health + ring.health).ToString();
    35.         damageOverall.text = (helmet.damage + chestplate.damage + leggings.damage + boots.damage + sword.damage + ring.damage).ToString();
    36.  
    37.         helmHealth.text = helmet.health.ToString();
    38.         helmDamage.text = helmet.damage.ToString();
    39.         chestplaHealth.text = chestplate.health.ToString();
    40.         chestplaDamage.text = chestplate.damage.ToString();
    41.         legginHealth.text = leggings.health.ToString();
    42.         legginDamage.text = leggings.damage.ToString();
    43.         booHealth.text = boots.health.ToString();
    44.         booDamage.text = boots.damage.ToString();
    45.         swoHealth.text = sword.health.ToString();
    46.         swoDamage.text = sword.damage.ToString();
    47.         riHealth.text = ring.health.ToString();
    48.         riDamage.text = ring.damage.ToString();
    49.     }
    50. }
    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.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,374
    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.
     
    CodeSmile likes this.
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,400
    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: https://docs.unity3d.com/Manual/LogFiles.html

    What Unity version are you on?
     
    CodeSmile likes this.
  4. diego_unity175

    diego_unity175

    Joined:
    Apr 6, 2024
    Posts:
    6
    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:
    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.
     

    Attached Files:

  5. diego_unity175

    diego_unity175

    Joined:
    Apr 6, 2024
    Posts:
    6
    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
     
  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,400
    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.
     
    Last edited: Apr 15, 2024
    CodeSmile likes this.
  7. diego_unity175

    diego_unity175

    Joined:
    Apr 6, 2024
    Posts:
    6
    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.
     
    Kurt-Dekker, CodeSmile and spiney199 like this.