"Prefabs" for classes, scriptableobjects?

I ran into ScriptableObjects recently, but I am not sure if I understand them correctly.
In my case I have an Attack class, which holds a timeline with frame data on which hitboxes should be spawned, etc.

alt text

I have written an editor extension to manipulate the timeline, add frames, determine framerate, etc.
Since this class is not a component, and it simply holds data, I thought it would be handy to let the extend the ScriptableObject class.

alt text

Everything went fine until I actually wanted to use the damn thing in runtime. I have a component that wants to get a copy (instance?) of this Attack class, with all the values that have been saved into this Scriptable Object so it can playback the Timeline class during an attack.

However, whenever I try to use ScriptableObject.CreateInstance(), all the fields are null.

alt text

Maybe I’ve misunderstood, and the ScriptableObject is only used to store data, and I should just feed the data manually into a new Attack class instance that I create in the component.

I’d like to simply use this ScriptableObject as some sort of prefab for a class, just being able to get a copy of the Attack with the variables as listed, and then directly reference the instance in the component.

Am I trying to do something unintended, should I somehow use a prefab for this, or did I simply implement the ScriptableObject incorrectly?

Thanks!

CreateInstance<> creates a new instance. It won’t have your data. You ought to reference the existing asset with the script like you would a GameObject. Then access its members. This makes sense because you can have >1 asset with the same ScriptableObject class type.

As far as I’m aware, there is no easy way to copy the instance, you would probably need to use AssetDatabase, which is editor-only anyway. ScriptableObjects are best thought of as data containers that don’t get changed at runtime.

Turns out this works, as for as I’ve tested for now
Attack attackCopy = Instantiate( attack );
//where attack is the reference to the scriptable object