Erroneous "cast would always fail" warning

Having a bug here on 4.10 where a cast node is warning me that NPC_NewGuard does’t inherit from NPC_Base, so the cast will always fail. However, NPC_NewGuard does inherit directly from NPC_Base, so naturally the cast doesn’t always fail. Here’s a screenshot of the cast (notice how it’s not failing - I’m hitting the breakpoint on the second return node there.

https://c1.staticflickr.com/1/651/23285800656_e4a797b76c_o.png

No big deal, but annoying.

I think this happens because at the time NPC_Base is getting compiled, NPC_NewGuard hasn’t been compiled yet (because it’s the child class).

In general, a cleaner way to deal with this kind of class-specific behavior is to override the function (GetGoodTimeToDoDialogGestures) for NPC_NewGuard and have the function return different values in the two implementations.

Hi everyone,

This is a known issue and is in our system as UE-7303. Currently it is not possible to cast to a child class from a base class. Unfortunately I do not have a timeframe of when a fix will be implemented, however I have updated the bug report to reflect that additional developers are experiencing this.

Hmm - interesting that the cast itself works fine then! Anyhow, thanks.

I have had the same issue,

If you want to get around this then you can make a variable with the Actor Reference you are casting,
It does not bring up any errors,

"Set “SelfREF” (Actor Reference) as “Self”

Cast to NPC_Guard with “SelfREF”

Hope this helps,

I’d strongly suggest this be resolved by just flagging such attempts as an error. As @ says, this should be implemented by overriding functions.

A class/blueprint should never make assumptions about even so much as the existence of child classes, let alone have a hard dependency on their definition. There is never a good reason to do this, updating the engine to allow it would just be encouraging misuse, as well as adding to existing circular reference issues in blueprints.

This issue has been cropping up for me a LOT, and has been for the past six months. Sometimes it works fine in the editor, but fails upon cooking. Please get it fixed soon, thanks!

This workaround worked for me. Thanks!

This workaround doesn’t fix the issue for me.
I cast to the child class from the parent CastTo node and I have the “child does not inherit from parent” warning message, even if I cast from a var referencing the parent actor instead.

I am getting the annoying “Cast will always fail” warning a lot with 4.14, much more than before, and even if the cast is not done inside the base class. This workaround is the only thing I tried that works to solve, but it is a very messy workaround so I hope the problem is solved soon.