# Cast always fails for inheritance

**URL:** <https://forums.unrealengine.com/t/cast-always-fails-for-inheritance/354620>\
**Category:** Blueprint\
**Tags:** inheritance, unreal-engine, cast, question, Blueprint\
**Created:** [April 18, 2016, 6:08pm UTC](https://forums.unrealengine.com/t/cast-always-fails-for-inheritance/354620 "2016-04-18T18:08:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Napoleonite](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Napoleonite](https://forums.unrealengine.com/u/Napoleonite)\
**Post date:** [April 18, 2016, 6:08pm UTC](https://forums.unrealengine.com/t/cast-always-fails-for-inheritance/354620/1 "2016-04-18T18:08:27Z")

</div>

As seen in the picture below PlayerCharacterBP DOES inherit from BaseCharacter\_BP. I also use it’s functions and variables so this is a bit strange.

I found this post from 4.10: [https://answers.unrealengine.com/questions/339295/erroneous-cast-would-always-fail-warning.html](https://answers.unrealengine.com/questions/339295/erroneous-cast-would-always-fail-warning.html) where it was logged under UE-7303. But how can I check the status of UE-7303 and has this still not been fixed?

 ![87335-cast+fails.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/6/4/7645221d2605ca1a1f6c609fa1fd6968d1b71c5a.png)

---

<div class="post-metadata">

**Author:** ![Cissoid](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cissoid](https://forums.unrealengine.com/u/Cissoid)\
**Post date:** [April 18, 2016, 9:17pm UTC](https://forums.unrealengine.com/t/cast-always-fails-for-inheritance/354620/2 "2016-04-18T21:17:26Z")

</div>

It’s the wrong way. You can cast the inherited class to baseclass, but the other way isn’t possible.  
The parent class doesn’t know which classes inherits. The parent class doesn’t have the properties and functions of  
the children.

How the Cast should work? The children has all public and protected properties of the parent.  
Maybe you’re looking for a boxing and unboxing mechanism.

Greetings

---

<div class="post-metadata">

**Author:** ![Napoleonite](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Napoleonite](https://forums.unrealengine.com/u/Napoleonite)\
**Post date:** [April 18, 2016, 9:44pm UTC](https://forums.unrealengine.com/t/cast-always-fails-for-inheritance/354620/3 "2016-04-18T21:44:50Z")

</div>

Ah indeed. You can’t cast the class to it’s child-class, only to it’s parent. Makes sense.

I could of course have a variable in BaseCharacter\_BP of the type PlayerCharacter\_BP and set it in the PlayerCharacterBP constructor so I have a reference to it from the parent. But that looks kinda silly.  
How do I box/unbox in Blueprints without using C++?

---

<div class="post-metadata">

**Author:** ![Cissoid](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cissoid](https://forums.unrealengine.com/u/Cissoid)\
**Post date:** [April 19, 2016, 9:08am UTC](https://forums.unrealengine.com/t/cast-always-fails-for-inheritance/354620/4 "2016-04-19T09:08:26Z")

</div>

it should work with the buildin types. take actor and cast it to your character.

Example: A Trigger gives you the other actor and you can cast it to whatever you expect.

In other languages you haves types they’re like boxes.

object mybox = mytype // boxing  
mytype = (MyType)mytype // unboxing you know the type you put in the box.

i hope it’s understandable.

---

<div class="post-metadata">

**Author:** ![Napoleonite](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Napoleonite](https://forums.unrealengine.com/u/Napoleonite)\
**Post date:** [April 19, 2016, 12:39pm UTC](https://forums.unrealengine.com/t/cast-always-fails-for-inheritance/354620/5 "2016-04-19T12:39:18Z")

</div>

The build-in types work. But the whole thing all together is strange at the very least. Also there is a case where you cast parent–\>actor–\>child where the engine gives me a warning about parent already being an actor and thus there should be no need to cast it to one. But I HAVE to cast it to the build-in type in order to cast it to a child-blueprint. Bug or me?

Casting from **Actor → child** works.

Casting **Parent → Child** always fails.

But casting **Parent → Actor → Child** only warns me that Parent is already an actor and that I do not need to cast it to Actor. Even though it should be the same as the above line. But it is not???

 ![87474-bp2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/1/0/6105b51f21c71a962118739c58f79007d629668c.png)

---

<div class="post-metadata">

**Author:** ![Imagine-Games](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Imagine-Games](https://forums.unrealengine.com/u/Imagine-Games)\
**Post date:** [January 13, 2020, 6:00am UTC](https://forums.unrealengine.com/t/cast-always-fails-for-inheritance/354620/6 "2020-01-13T06:00:38Z")

</div>

\*Edit, doing what you recommended did not fix it for me… but updating to 4.24.2 magically did…  
old post: funnily enough i had gone all the way from 4.14 to around 4.21 using this parent cast to child and it worked with no warnings but now in 4.24 it warns me about the cast failing. glad i came across your post , in this case i’ll do what you did and cast from parent to his actor type and cast to the child… should work as you said…

---

<div class="post-metadata">

**Author:** ![dubako](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dubako](https://forums.unrealengine.com/u/dubako)\
**Post date:** [March 14, 2020, 2:10am UTC](https://forums.unrealengine.com/t/cast-always-fails-for-inheritance/354620/7 "2020-03-14T02:10:49Z")

</div>

epic needs to fix these important bugs before adding any more features for Magic Leap and ansel photography and all this stuff that no one uses

---

<div class="post-metadata">

**Author:** ![dubako](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dubako](https://forums.unrealengine.com/u/dubako)\
**Post date:** [March 14, 2020, 2:27am UTC](https://forums.unrealengine.com/t/cast-always-fails-for-inheritance/354620/8 "2020-03-14T02:27:31Z")

</div>

okay so this explains how to get around this. hope it helps someone out.

 ![297839-bp-solution-answer.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/4/8/048dc07698db9a128cd9f95dbac2f41f188b9edd.png)

---

<div class="post-metadata">

**Author:** ![Ozgurr\_Ozkann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ozgurr\_Ozkann](https://forums.unrealengine.com/u/Ozgurr_Ozkann)\
**Post date:** [March 19, 2023, 8:12pm UTC](https://forums.unrealengine.com/t/cast-always-fails-for-inheritance/354620/9 "2023-03-19T20:12:33Z")

</div>

I am getting Unreal Course and the lecturer did cast from the parent class to the child class. How did it worked ? I searched a lot and the answers the I found as you said. But what lecturer did confused my mind. Do you have any idea about that ?
