How can I cast all Child Classes blueprints for weapons to the Workbench for my Game?

Hi, I am trying to make a workbench mechanic, but I want to cast my weapons for the status of ammo and current damage for each weapon. How can I do this without errors for reference?

If you could give me an answer to that, I would appreciate it.

If all your weapons are children of a base weapon class, you shouldn’t need to cast to all children. Just cast to the parent class. The parent class should have the vars for damage, ammo count/capacity, ammo type, and such.

dont cast to every child weapon class, that defeats the parent.

make a Weapon base class (or interface BPI_Weapon) with functions GetAmmo, GetDamage etc, have all weapons inherit it. then in workbench just Get the actor and Cast to WeaponBase once, or Call BPI_Weapon function. one cast covers all children.

if you need type-specific logic add a WeaponType enum on the base and branch on that, dont branch on class.

Okay, but what about saving the weapon damage upgrade with the base weapon for other weapons when it didn’t save?

the upgrade was never going to live on the base weapon, because blueprint class defaults are compile-time data, not a save file. any value you set on an actor instance (details panel or at runtime) dies with that actor, since every spawn reads fresh defaults from the class. the base weapon has nowhere to persist it.

three separate problems to check:

  1. design-time edits: if you changed damage on a placed weapon actor in the level, that only modified that one instance. set the value in the base weapon Class Defaults instead and every child inherits it.
  2. child overrides: if a child blueprint has its own value typed into the damage variable, it permanently overrides the parent, so editing the parent default will never reach that child. open the child, select the variable in the details panel, right click and Reset to Default. from then on parent edits cascade to it again. the little override arrow next to the value tells you it is shadowing the parent.
  3. runtime upgrades: workbench upgrades must go into a SaveGame object, not onto the weapon actor. make a struct (WeaponSaveData: WeaponClass, UpgradeLevel, Damage, Ammo), keep an array or map of them on your SaveGameObject and write it on every upgrade. when a weapon spawns or loads from inventory, look up its entry by class and apply the saved damage after BeginPlay. the actor is disposable, the save data is the source of truth.

so the flow is: sane defaults in the base class, overrides only in children that genuinely differ, runtime upgrades only in the save file keyed per weapon class. never try to persist state on the actor itself.