# CAST failed when using child of the CASTED parent character class

**URL:** <https://forums.unrealengine.com/t/cast-failed-when-using-child-of-the-casted-parent-character-class/467087>\
**Category:** C++\
**Tags:** casting, inheritance, cast-failed, unreal-engine, question\
**Created:** [June 22, 2020, 7:32am UTC](https://forums.unrealengine.com/t/cast-failed-when-using-child-of-the-casted-parent-character-class/467087 "2020-06-22T07:32:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BEnSon1101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BEnSon1101](https://forums.unrealengine.com/u/BEnSon1101)\
**Post date:** [June 22, 2020, 7:32am UTC](https://forums.unrealengine.com/t/cast-failed-when-using-child-of-the-casted-parent-character-class/467087/1 "2020-06-22T07:32:55Z")

</div>

I have a parent **Character class**

I have a child **Character class**

I have a respawn function in a **PlayerState class** which CASTS to the **Parent Character Class**

because i am using the **Child Character Class** and not the **Parent Character Class**

**The Cast Fails** and the function doesn’t complete

---

<div class="post-metadata">

**Author:** ![EvilCleric](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EvilCleric](https://forums.unrealengine.com/u/EvilCleric)\
**Post date:** [June 22, 2020, 10:03am UTC](https://forums.unrealengine.com/t/cast-failed-when-using-child-of-the-casted-parent-character-class/467087/2 "2020-06-22T10:03:05Z")

</div>

So, you have:

- the parent class: X
- the child class: Y
- you respawn Y and you are trying to cast it to X?

---

<div class="post-metadata">

**Author:** ![BEnSon1101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BEnSon1101](https://forums.unrealengine.com/u/BEnSon1101)\
**Post date:** [June 22, 2020, 10:57am UTC](https://forums.unrealengine.com/t/cast-failed-when-using-child-of-the-casted-parent-character-class/467087/3 "2020-06-22T10:57:39Z")

</div>

the Respawn function is in PlayerState

**X** which has a respawn function that is linked to the respawn function CALL in player state

**Y** doesnt have any code in it **I was relying on inheritance giving Y the same stuff as X**

i assumed that **Y the Child character class** would make the cast return **True** because its **parent which is X** is the class that the cast in the **PlayerState** is casting to

I was thinking of a **possible solution** which would be insted of casting the **Respawn Function** to The **Character parent class** i would cast it to **ACharacter** which is generic and would return successfull for all **different Child character classes in game**

would this be correct solution

---

<div class="post-metadata">

**Author:** ![BEnSon1101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BEnSon1101](https://forums.unrealengine.com/u/BEnSon1101)\
**Post date:** [June 22, 2020, 11:01am UTC](https://forums.unrealengine.com/t/cast-failed-when-using-child-of-the-casted-parent-character-class/467087/4 "2020-06-22T11:01:57Z")

</div>

basically would casting to **ACharacter** instead of direct reference **To the parent character class** return true for all the Child Character classes

---

<div class="post-metadata">

**Author:** ![k\_Rave](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@k\_Rave](https://forums.unrealengine.com/u/k_Rave)\
**Post date:** [June 22, 2020, 11:32am UTC](https://forums.unrealengine.com/t/cast-failed-when-using-child-of-the-casted-parent-character-class/467087/5 "2020-06-22T11:32:19Z")

</div>

I think it would be easier to paste the relevant parts of your code (like the class declarations, the respawn function, the respawn function calling instruction), isn’t it ?

---

<div class="post-metadata">

**Author:** ![BEnSon1101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BEnSon1101](https://forums.unrealengine.com/u/BEnSon1101)\
**Post date:** [June 23, 2020, 7:17am UTC](https://forums.unrealengine.com/t/cast-failed-when-using-child-of-the-casted-parent-character-class/467087/6 "2020-06-23T07:17:50Z")

</div>

**the answer i was looking for is in this post**

[https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/104582-does-casting-to-the-parent-class-affect-children](https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/104582-does-casting-to-the-parent-class-affect-children)

what i did to fix it was instead of casting to **AParentCharacterClass** i casted to **ACharacter**

Using **ACharacter** sucsessfully casted to parent class and all child classes
