Everyone says ScriptableObjects can be used for inheritance.
- I create the scriptable object with Factory:
ScriptableObjectFactory/Assets/Editor at master · liortal53/ScriptableObjectFactory · GitHub
The asset is successfully saved on project.
-
I assign the scriptable object to my monobehavior.
-
Everything works fine.
-
I hit play mode.
-
Everything works fine.
-
i exit play mode.
-
Everything works fine.
-
i switch to another scene or close unity editor with X button at top right.
-
Scriptable objects get the message :
“The associated scripts can not be loaded …”
And monobehavior link shows : None (MyClass)
I am frustrated, why do my scriptable objects go missing?
Ps. I am not willing to remove OOP concepts, i rather switch to another game engine.
Edit / Progress: Still havent solved the problem but …
If in step 1 i use attribute [CreateAssetMenu],
The asset is still saved in project like before.
However the problem in step 9 gets fixed The monobehavior keeps the correct links to those assets and works perfectly. But now occurs problem 10.
- Unrefered scriptableobjects created by [CreateAssetMenu] become missing, cannot be used by the monobehavior, they still consume disk space in my project.
So to conclude every scriptableobject created by [CreateAssetMenu] is “Safe” if refered by another monobehavior, but those unrefered get deleted, even thought it persists in the projects and takes up space.
Code:
[Serializable]
public class MyCameraType : ScriptableObject
{
public virtual void Init(MonoBehaviour mono) {}
}
[Serializable]
public class TopDownCamera : MyCameraType
{
public override void Init(MonoBehaviour mono)
{
Transform camera = Camera.main.transform;
camera.eulerAngles = new Vector3(90, 0, 0);
camera.position = new Vector3(0, 30, 0);
}
}
[Serializable]
public class ThirdPersonCamera : MyCameraType
{
public override void Init(MonoBehaviour mono)
{
Transform camera = Camera.main.transform;
camera.eulerAngles = new Vector3(0, 0, 0);
camera.position = new Vector3(0, 10, -20);
}
}
Edit: Revision 1: Applied Bunny83 code changes. Problem Still Persists.
Edit: Solution: Placing each script in a seperate file, fixed the problem.