CAST failed when using child of the CASTED parent character class

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

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 ?

So, you have:

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

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

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

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

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