Cast fails seemingly random

Hi,

so, i am setting up an inventory system for a Third Person RPG and along with this, a weapon swap from secondary weapons to primary weapon and vice versa. The code in the picture seems to work fine until a certain point. After around 20 consecutive weapon swaps one of the casts to “base weapon” suddenly fails.

Has anyone any idea what i am doing wrong?

must be spawning a weapon that does not inherit from your base weapon class. Do all your weapons inherit from the same class?