- Home /
Can not load ScriptableObject
Hi,
The problem I'm having only happens in build. In editor it works fine.
So I have several scriptableObjects, here's one of the class:
[System.Serializable]
public class Affected{
public string effect;
public GameObject source;
public float num;
public int dur;
public float timer = 0f;
public Affected(string theEff, float theNum, float theDur, GameObject theSource){
effect = theEff;
source = theSource;
num = theNum;
dur = Mathf.CeilToInt(theDur);
}
}
[System.Serializable]
public class SkillInstance{
public string name = "";
public float variance = 1f;
public bool physical = false;
public SkillInstance(string n, float p, bool pm){
name = n;
variance = p;
physical = pm;
}
}
[System.Serializable]
public class Skill{
// The type of skill, with list of effect
public string name;
public string desc;
public AimType aimType = AimType.Self;
public CastType castType = CastType.Click;
public ReleaseType release = ReleaseType.Apply;
public SpiritType element = SpiritType.Fire;
public List<string> effects = new List<string>();
//public float scale = 0f; // Various effect depending on OnHit
//public Entity source = null;
}
I populated the scriptableObject that I made. Then in a Manager Gameobject, I have public SkillDatabase which I assigned the scriptable object there. Somewhere in the manager I have:
if(!skillDB)
Debug.LogError ("SkillDB missing");
if(skillDB)
foreach(Skill sk in skillDB.skills){
Formula.allSkill.Add(sk.name, sk);
}
So Formula.allSkill (a static Dictionary) will have that now(maybe this is unnecessary. I just want all the skills to be in a Dictionary form). Anyways, things works in editor. In build, however, the error could either be - a script behaviour has a different serialization layout when loading - Script attached to in scene '' is missing or no valid script is attached. UnityEditor.HostView:OnGUI() webplayer - An error that says a file is corrupt. Try removing that and restart Unity.
I've tried several things like putting the scriptableObjects in Resources folder, and have skillDB = Resources.Load("SkillDB") as SkillDatabase;
The scriptableObject is always null.
The thing is, all the scriptableObjects are always having a "missing script" error in the editor, right after I just launch Unity. But pressing play once, and stop, will make the scriptableObjects seem to "remember" again the values in it. I really don't know what's causing this. So, maybe in build, this is what's actually happening. All the scriptableObjects are having the "missing script" error.
Anyone know what's happening?
The only thing I'm thinking might cause this is because I put some #if UNITY_EDITOR, but I only put these in scripts that deals with creation of the scriptableObjects itself(just to create the asset). So, I don't think this is what's causing it...