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.