Hi
When I intend to use scriptableobject in my game, I have a doubt how to use it correctly
For example I have a soldier that has different classes like MoveComponent, AttackComponent,…
public class MoveComponent:MonoBehaviour{
float currentSpeed;
float currentHP;
float maxSpeed; // initialized by ScriptableObject
float maxHP; // initialized by ScriptableObject
Wepoan[] weapons; // initialized by ScriptableObject
[SerializeField]
MoveSoldierSO moveSoldierSO;
[SerializeField]
HealthSoldierSO healthSoldierSO;
[SerializeField]
WeaponSoldierSO weaponSoldierSO;
void Awake(){
maxSpeed=moveSoldierSO.maxSpeed;
maxHP=healthSoldierSO.maxHP;
weapons=weaponSoldierSO.weapons;
}
void OnEnable(){
}
}
My questions:
1- I do not know whether I make a scriptableobject for a soldier like below:
[System.Serializable]
public class SoldierSO:ScriptableObject{
public float maxSpeed;
public Wepoan[] weapons;
public float maxHP;
//...
}
or separate them:
[System.Serializable]
public class MoveSoldierSO:ScriptableObject{
public float maxSpeed;
}
[System.Serializable]
public class HealthSoldierSO:ScriptableObject{
public float maxHP;
}
[System.Serializable]
public class WeaponSoldierSO:ScriptableObject{
public Wepoan[] weapons;
}
If I separate them, I can use them in suitable components instead of sending the complete scriptableObject to them(components)
It is better to break them in level of components or one field(every scriptableObject contains only one field like maxHP, maxSpeed,… because I see that some people create scriptableObjects that have only one field)?
public class FloatVariable:ScriptableObject{
public float value;
}
// it can be maxHP,maxSpeed,etc
they are dragged and dropped on an inspector directly
I see a scriptableObject as a tool to inject data to my classes but I faced codes a lot that send GameObject to a ScriptableObject and initialize them inside it:
public class MoveSO:ScriptableObject{
[SerializeField]
float maxSpeed;
public void Initialize(GameObject _obj){
MoveComponent moveBehaviour=_obj.GetComponent<MoveComponent>();
moveBehaviour.maxSpeed=maxSpeed;
}
}
Even more, they bring all functions inside a scriptableobject and call them from monobehaviour functions(in update or OnCollsionEnter or ClickEvent,…)
I am confused which way is suitable
Thank you