In Unity am creating an item system using the base class:
[CreateAssetMenu]
class ItemBase : ScriptableObject(){
public string ItemName;
public Sprite ItemSprite;
void Spawn() {
//Spawn Item Using The Sprite
}
}
and then I am using the CreateAssetMenu to right click in my project folder for each item I want to add to the game and then assign their values in the editor.
When i drag my object from the editor onto a game object, everything works fine.
The issue im having is that I cannot figure out how to actually instantiate these at runtime from a script.
When I try to reference it like a class, the class is not found, when I add a script that mirrors the created item, the properties set by the editor are null upon instantiation.
Ideally what id like to do is something like:
Right click and create new ItemBase called FishingRod from editor
Assign name and sprite in editor
\\Instantiate From Script FishingRod rod = ScriptableObject.CreateInstance(typeof(FishingRod)); // Properties should be the properties set by editor FishingRod.Spawn(); // Inserts Item Into Game
But when I instantiate the class, its properties are null;
rod.ItemSprite //is null
rod.ItemName //is null