Advanced Weapon inventory using Scriptableobject?

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.

1 Like

@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… :slight_smile:

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)

He’s saying you could (to start working on it) use one with numerous fields and/or different fields…

say I have a sword, but my general ā€˜weapon’ has ammo… the sword object has ammo but i just ignore it.
That’s what he meant, I’m pretty sure.

1 Like

:slight_smile: 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 :slight_smile:

1 Like

Hello !

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 ?