- Home /
ScriptableObject Inheritance Serialization failure
Hi,
Here is the issue i'm facing :
public class Shapes : ScriptableObject {
GetShape(){}
}
[CreateAssetMenu(fileName = "Quad",menuName = "Shapes/Quad")]
[System.Serializable]
public class Quad : Shapes {}
[CreateAssetMenu(fileName = "Star",menuName = "Shapes/Star")]
[System.Serializable]
public class Star : Shapes {}
This is all in the same file.
Creating the assets works fine, but when i restart the editor or leave play, they do not get reloaded properly, that is because the script file associated to the scriptableObject asset is not set.
In the Yaml you find : m_Script: {fileID: 0}
instead of normally : m_Script: {fileID: 11500000, guid: e9c59ec9df3a4c942919c13d32e8cd99, type: 3}
Which appears correctly if those classes are in separated files.
I have 5 or 6 different base shapes, some shapes instanciators etc... I do not want to put them in different files, it is bad for my code flow, as i have a better view and understanding of the class hierarchy by having them all defined in the same file.
To go further is there any project for Unity to actually dissociate the meta of the serialized classes and prefabs from their script file GUID? and instead associate it to a GUID of the class itself? (like the class inheritance hierarchy that you can find here : m_EditorClassIdentifier: Assembly-CSharp::Star
)
Why is it that Unity still links the script file to anything editor related, that makes inheritance very cumbersome...
Edit : If i correct the YAML by hand then it works and reload properly but i cannot fix the YAML by hand for any number of instances... that is a hack, if someone knows a solution to actually edit the .asset file by code when the object is created and fix this issue that would be great.
Furthermore, i use the GUID of the script where i defined the "Shapes" class but for any other configuration the GUID would be different.
It is a great limitation that Unity relies on the File names and Files GUIDs for the logic.
And also, if the editor serialize to text option is not set then i find myself with a binary and cannot fix that issue.
If you have found out something about this that will be awesome!
Your answer
Follow this Question
Related Questions
Get script with GetComponent, but as base class 1 Answer
Adding script during runtime 2 Answers
How can I load in data for a derived type class from a CSV? 0 Answers
inheritance - problem setting class variable from external call 0 Answers
How do I best access a child script through a parent script when using inheritance 0 Answers