Hi all. I would like to implement a weapon inventory using scriptableobject. Every weapon is id,name,description,attackpoint but some weapons have reload time,some of them have magazines(magazine capacity),etc
How can I implement all weapons scriptableobject. I would like to access them using id.
Do I need to define several classes for every type of weapons?
I defined classes using interfaces and abstract classes but I need to initialize the seperate fields using scriptableobject
public class WeaponBase:Monobehaviour{
int id;
Type type;
string description;
int attackPoint;
}
public Interface IReload{
float reloadSpeed;
}
public interface IConsumableAmmo{
int numAmmo;
}
public class Weapon1:WeaponBase,IReload,IConsumableAmmo{
}
public class Weapon2:WeaponBase{
}
public class Weapon3:WeaponBase,IConsumableAmmo{
}
...
I wrote only the fields of the classes.Now How can we implement scriptableObjects(need different classes for every type of weapons)?
Donāt get too far ahead of yourself. Keep it simple. Make one ScriptableObject called Weapon, and for now just put all the fields you want in there.
Eventually you will reach a point this wonāt scale well. When it reaches that point, refactor. Until you reach that point, you will not have enough information to make good choices about how to break it down. You must use it āfor realā before you get a feel for where your chokepoints will be.
With Unity, refactoring a code/data symbiosis like this is trivial because you can always just make an editor script that āconvertsā the old scriptable objects to the new data shape, and run that program once, even if you have 10,000 different weapons.
ALSO⦠you are using good source control, right? Thatās also quite handy⦠and be sure to use āForce Textā asset serialization so you can see the diffs of each change as you commit it. I recommend git for source control with Unity and thereās lots of tutorials on setting it up correclty.
@Kurt-Dekker made some good points (some I even forget myself at first). Start off easy-going and expand when needed. ScriptableObjects sound perfectly good for setting up your weapons, and an instance variable of your weapon if it needs changing statsā¦
Thank you but I didnāt understand! How can I have only one scriptableobject with different type of weapons(some of them have extra fields and the others doesnāt)
So we have only one scriptable object with many fields (attackpoint,attackRatio,NumAmmo,Range,ReloadSpeed,CoolDownTime,ā¦)
and ignore some of them for special weapons? Is it suitable to do for only initializing data (Scriptableobject)? Right?
because If we implement all classes like as you said, it ruins oop designs
Ya, I think heās saying itās okay to start out small and build and ⦠let your game (and its design) evolve gracefully rather than building what you think will be great for everything now and it not working out. Thatās the general idea I got from his postā¦
Heās not saying always do that (or keep doing that forever)⦠just to help you get going and youāll see where and when you could use change
I am in the same situation as mahdii, but I donāt want to āignoreā different field when I donāt need it, as this is orthogonal to every POO design and I want to make my ScriptableObjects fool-proof.
Is there a solution to actually solve this problem ?