Upgradable Weapon

The UpgradableWeapon is a Weapon that can level up. Each level is a Barrel Config that it applies to its barrel, so a pistol can become a triple-shot pistol without swapping prefabs.

Add Component: Glowing Rifts > Modular Weapon > Upgradable Weapon

✅ Ideal For

  • Power-ups and pickups
  • Roguelite or arcade weapon progression
  • Shop upgrades

📐 Inspector Overview

Aside from the Weapon fields, the upgradable weapon adds:

FieldDescription
LevelsThe barrel config of each level, starting at level 0
Start LevelThe level the weapon starts at (0 is the first config in Levels)
On Upgraded (Int32)Invoked after the level changes, with the new level

⚙️ How It Works

  • On Awake, the weapon applies the config of its Start Level to the barrel.
  • Upgrade() goes up one level and does nothing at the max level.
  • SetLevel(level) switches to any level, clamped to the levels available.
  • Each level change calls barrel.ApplyConfig and raises On Upgraded.

Tip

Wire a pickup’s event to Upgrade() to level the weapon up with no code. Use On Upgraded to update the HUD or play a sound.

Tip

To add muzzles as the weapon levels up, hook On Upgraded to a script that calls barrel.SetSpawnPoints.

🧑‍💻 Scripting

using GlowingRifts.ModularWeaponSystem;

public class UpgradeOnKill : MonoBehaviour
{
    [SerializeField] private UpgradableWeapon _weapon;

    public void OnEnemyKilled()
    {
        if (_weapon.level < _weapon.maxLevel)
            _weapon.Upgrade();
    }
}
MemberDescription
int levelThe current level, starting at 0
int maxLevelThe highest level, from the number of configs in Levels
void Upgrade()Goes up one level
void SetLevel(int newLevel)Switches to a level, clamped to the levels available