- Home /
[SerializeField] Not Working Properly?
I'm having an issue getting SerializeField working properly with my editor script.
I have a main class called "SAC", I then have sever sub classes called "SACObject", "SACInt" (which extends "SACObject"), and SACSetting. I also have an array of the SACSetting's. (It is not initialized just like this, this is just an example). The code looks like this:
public class SAC : MonoBehaviour {
[SerializeField]
SACSetting[] settings = new SACSetting[] {};
[Serializable]
public class SACSetting {
public SACObject val;
public SACSetting(SACObject val){
this.val = val;
}
}
[Serializable]
public class SACObject {}
[Serializable]
public class SACInt : SACObject {
int val = 0;
public SACInt(int val){
this.val = val;
}
}
}
Now, When I modify the "Settings" array using my custom editor script, It works just fine in editor. But, Once I press "Play" on the game, the "Val" variable in each of the SACSetting classes turns into just a SACObject instead of a SACInt.. And it refuses to cast back to a SACInt.. I know this seems a little confusing, But any help would be awesome. If you need any more info you can let me know.
Answer by Barsonax · Jan 01, 2016 at 10:57 PM
I think if you let SACobject inherit from scriptableobject it should work. Like this:
public class SACObject : ScriptableObject {}
http://docs.unity3d.com/ScriptReference/ScriptableObject.html
Your answer
Follow this Question
Related Questions
Access another objects property in an editor script 1 Answer
Is there a way to get the names of all SerializedProperty objects in a SerializedProperty object? 1 Answer
How to properly serialize fields and store them for use in play mode? 1 Answer
Why can't a MonoBehaviour subtype with generic arguments be serialized in a list since Unity 4.5? 0 Answers
Display function parameters in inspector 0 Answers