Scriptable Object bug ?
Hi guys, here is my script :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEngine;
[CreateAssetMenu (menuName = ("ItemAsset"))]
public abstract class ItemAsset : ScriptableObject {
public String Name;
public Texture2D Icon;
public ItemPrefab Prefab;
public Int32 Cost;
public Int32 DurabilityMax;
public abstract Boolean CanStackInInventory { get; }
public Item CreateNewItem() {
Item item;
item = Create();
item.Id = Guid.NewGuid();
Debug.Assert(item.Asset != null);
Debug.Assert(item.Data != null);
return item;
}
protected abstract Item Create();
}
I can't create the object using the create menu, I get an error "the classe needs to derive from Scriptable Object... -_-
I'm running Unity perso 5.4 Any idea ?!
Answer by AurimasBlazulionis · Dec 26, 2016 at 06:35 PM
Abstract. Why? Why is the class abstract? You don't really use abstract with MonoBehaviours, so you shouldn't with ScriptableObjects.
Well, my class is abstract because I want other to derive from it and override some properties.
Doesn't it make sense ?
ScriptableObjects (or $$anonymous$$onoBehaviors) can be abstract, but you can't create/add instances of them, just like any other abstract class. You need to derive some concrete class that you would create from the menu.
Your answer
Follow this Question
Related Questions
Abillity system for turn based strategy 0 Answers
Custom inspector - How to serialize scene objects in ScriptableObject? 0 Answers
Why "the associated script can not be loaded" for some Scriptable Objects? 1 Answer
Serialization issue after updating Unity from 2018.2.1 to 2019.2.6 1 Answer
type mismatch on texture 2D inside scriptable object 0 Answers