It's odd, as it is now, you should get a CS0103 compiler error, due to the fact that you need to write:
myScriptable = ScriptableObject.CreateInstance<MyScriptable>();
Moreover, if the
MyScriptable class it's inside the
MyComponent script attached to a game object, you'll get a warning - to get rid of it you need to cut the
MyScriptable class code from it and put it in its specific script, named ofc
And remember that the
myScriptable instance will be serialized in edit mode as soon as you finish compiling the script for the first time, since you put
You're getting the
Type Mismatch error in the prefab of the game object with the
MyComponent script, and that's normal, since prefabs can't get a reference to any kind of instances in the hierarchy of the scene, but only to assets.
For example, if you create a game object in the hierarchy, then attach the
MyComponent script, you'll be able to access the
myScriptable instance, by double-clicking on the
My Scriptable field of the script in the inspector.
But, if you now create a prefab from it, you'll get the
Type Mismatch error in the field of the script attached to the prefab.
And you can't really escape from it: if you want to have a reference in the prefab, you HAVE to create a
myScriptable asset which can be then referenced by the prefab.
Of course you can do that by using
just after the
CreateInstance method in
MyComponent, or you can add the
[CreateAssetMenu] attribute in the
MyScriptable script, so you can create any asset you want in the editor, and then drag-and-drop it in the reference field of the prefab.
That's pretty much it, hope it helped.