As title.
I have a scriptable Object with all the info for a weapon.
I would like to instantiate at runtime a clone of the scriptable Object and save it to a new asset. So that if I modify the clone, the original remains intact
As title.
I have a scriptable Object with all the info for a weapon.
I would like to instantiate at runtime a clone of the scriptable Object and save it to a new asset. So that if I modify the clone, the original remains intact
To save any asset, you can use AssetDatabase.CreateAsset()
. This operation can be done only in editor. Documentation
Do you need to save it as an asset to use in the editor later? Or do you not want to alter the OG scriptable object but have changes made to one in scene?
If latter, you should Instantiate the scriptable object instead of referencing it.
For example this will change the actual Scriptable Object in Editor
public MyClass : Scriptable Object
{
public string title;
}
public SomeClass : Mono
{
[SerializeField] MyClass scrObj;
void Start()
{
scrObj.title = "Bert";
}
}
Where this, will only change the one in the scene, not the editor
public SomeClass : Mono
{
[SerializeField] MyClass scrObj;
MyClass useMe;
void Start()
{
useMe = Instantiate(scrObj);
useMe.title = "Bert";
}
}