I have the following:
public class Item
{
[SerializeField]ItemData _data;
public ItemData data { get { return _data; } }
}
public class Weapon : Item
{
[SerializeField]WeaponData _data;
public WeaponData data { get { return _data; } }
}
public class ItemData : ScriptableObject { }
public class WeaponData : ItemData { }
It seems like a pretty common setup to me, data is separated from logic classes - and I can use single scriptable objects to define stats for alot of items.
However, Unity gives me this error message:
The same field name is serialized multiple times in the class or its parent class. This is not supported:
I understand what's going wrong, but I don't get how to work around it, I want the data objects to inherit so I don't need to keep two (or more, further into inheritance) separate data objects per weapon.
I also need the item inheritance for inventory/merchant list management. Using hiding screws up the serialization of the baseclass, which means I can't create default items - not feasible.
The issue is the same when using public instead of [SerializeField].
Any pointers?
Weapon
object instanced, calledweap
and I doweap.data
, what should I get back? AnItemData
or aWeaponData
? \$\endgroup\$