ScriptableObject.CreateInstance don't works

Hello everyone,
I have a scriptable object that store all my weapon’s data :

[CreateAssetMenu(fileName = "New weapon", menuName = "Weapon")]
public class WeaponData : ScriptableObject
{

    public string name_;

    public Sprite sprite;

    public bool ranged;
    public int capacityPrimary;
    public int capacitySecondary;

    public int energy;
    public float energyRestore;
    public int cast;//how many different spells are cast every time the player fires
    public float cooldown;
    public float reload;

    public float durability;

    SpellsData[] spellsArrayPrimary;
    SpellsData[] spellsArraySecondary;

I want to create a weapon from this scriptable object, i tried this :

        var thing = ScriptableObject.CreateInstance<WeaponData>();
        thing.name_ = "fnjkejzvcbcvjhbcvjhbjvhbejkrvbe";
        thing.energy = 100;

But the new scriptable object isn’t displayed nowhere.
Can you help me?

CreateInstance only creates the ScriptableObject in memory, if you want it as an asset in your project you need to use AssetDatabase.CreateAsset as well Unity - Scripting API: AssetDatabase.CreateAsset

1 Like
        WeaponData example = ScriptableObject.CreateInstance<WeaponData>();
        string path = "Assets/Resources/Weapon/weaponA.asset";
        AssetDatabase.CreateAsset(example, path);

It works with this, thank you

1 Like