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