Start method does not run on disabled component

As far as I am concerned, Start method of the disabled Fighter component does not run.
That’s what I can come up with after banging my head on null reference exception.

In the Fighter.cs Start method (at least in my version of this method), a lot of stuff is going on (weapon initializing etc).
If we launch the game with a disabled Fighter component, when this component gets enabled, the OnEnable method does run, but the Start method had not run (and will never do).
Seems that the Start method runs once, before the first update, if the component is enabled.
I solved my problem with a if statement on the OnEnable method, checking if the fighter’s weapon had already been set. If not, I call Start.

[...]

 private void OnEnable()
 {
     baseStats.onLevelUp += UpdateDamage;
     if(equipment!=null)
     {
         equipment.equipmentUpdated += UpdateWeapon;
     }

     if(currentWeapon == null)
     {
         Start();
     }
 }

 private void OnDisable()
 {
     baseStats.onLevelUp -= UpdateDamage;
 }


 private void Start()
 {
     damageDealer = gameObject;
     defaultWeapon = Resources.Load<WeaponConfig>(defaultWeaponName);

     timeSinceLastAttack = timeBetweenAttack;
     if (currentWeapon == null)
     {
         EquipWeapon(defaultWeapon);
     }
 }

[...]

Hope this may help some lost souls :slight_smile:

Privacy & Terms