# Cast fails seemingly random

**URL:** <https://forums.unrealengine.com/t/cast-fails-seemingly-random/439598>\
**Category:** C++\
**Tags:** casting, unreal-engine, fail, question\
**Created:** [December 16, 2018, 12:01pm UTC](https://forums.unrealengine.com/t/cast-fails-seemingly-random/439598 "2018-12-16T12:01:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BigVulpes](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BigVulpes](https://forums.unrealengine.com/u/BigVulpes)\
**Post date:** [December 16, 2018, 12:01pm UTC](https://forums.unrealengine.com/t/cast-fails-seemingly-random/439598/1 "2018-12-16T12:01:03Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [December 16, 2018, 11:27pm UTC](https://forums.unrealengine.com/t/cast-fails-seemingly-random/439598/2 "2018-12-16T23:27:25Z")

</div>

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