Engine Not Recognising Parent Blueprint Classes

I am trying to cast an instance of a parent object (masterCommander) to it’s child (humanCommander):

I am getting this warning when doing so:

But humanCommand most definitely DOES inherit from masterCommander:

And when I click to ‘Find Content in Parent Browser’ in the image above it indeed takes me to the one and only masterCommander.

Side note: I am also unable to save the blueprint but have had absolutely no luck discovering the cause (even reverting to old versions of my project does nothing…) so this could be it? See below

Can anyone help me fix this please?! Thanks in advance :slight_smile:

Wait… You’re trying to cast an instance of the parent to the child blueprint? Thats not the way it works…

For example, you can cast an instance of HumanCommander to MasterCommander, because HumanCommander inherits from MasterCommander.

You CANT cast from MasterCommander to HumanCommander, because MasterCommander does not inherit from HumanCommander.

That’s what I thought too, but if you think about it you have no need to cast a child to it’s parent- by definition it’s already a ‘parent’ in the same way a puppy is a dog. He should be able to cast from type MasterCommander to HumanCommander because HC is a child of MC, so it’s possible that any given MC type is a HC (but not ALL MC are HC).

While this is possible to cast a MC type to HC, I believe his mistake is in making the cast from the parent BP. I don’t know why you would do this in this way. However, I think this is an issue where the engine won’t handle BP Inheritance beyond two levels. (Parent and Children). I recognize these class names, and if this is what I think it is and MasterCommander has a BP parent, that would be your issue.

nwilcoxnz, what is the parent of MasterCommander?

"so it’s possible that any given MC type is a HC (but not ALL MC are HC). "

I think you mean any given HC type is a MC

Then you go on to say “While this is possible to cast a MC type to HC” I dont think this is possible.

is my explanation of what I think is happening. Say were dealing with player characters, and I have:

a parent called MasterCharacter

a child called BlueCharacter

another child called RedCharacter

The character can either be a RedCharacter or BlueCharacter. If I call get player character, without knowing whether the player is a RedCharacter or BlueCharacter, I can cast to MasterCharacter, and still call functions and things out of this.

But say the character is just a regular old MasterCharacter. I then will not be able to cast it to BlueCharacter, or RedCharacter, because the MasterCharacter inherits from neither.

And I know the engine will handle Inheritance beyond two levels, because I have a project with 4 levels of parents/children.

Well I know the engine can handle arbitrary levels of Inheritance, as the engine itself does this. However BP seems to not be able to. Having this hierarchy will cause an error if you try to package:

(BP CLASS) Pickupable → Base Class (weapon) → Specific Weapon (data only)

Pickupable → Base Class (Equipment) → Specific Equipment (data only).

Where Pickupable has several children, and the children are base classes for more specific items.

This doesn’t actually cause any issue during PIE or during BP work. As a matter of fact, if I make a variable of type Base Weapon class, I can set that variable to any Specific Weapon class in engine, use it to drive spawn actor nodes, and even use the spawned reference in later functionality. I can PIE and have no issues or errors whatsoever. I can remake the logic throwing the packaging error, and it still persists.

“The character can either be a RedCharacter or BlueCharacter. If I call get player character, without knowing whether the player is a RedCharacter or BlueCharacter, I can cast to MasterCharacter, and still call functions and things out of this.”

Sure.

"But say the character is just a regular old MasterCharacter. I then will not be able to cast it to BlueCharacter, or RedCharacter, because the MasterCharacter inherits from neither. "

Also, yes. If the class in question is MC, then the cast CAN fail.
But if you only know that the class MUST be a MC, the cast will tell you if it HAPPENS to be a Red or a Blue character. Say you have an overlap event on a box. You cast to MC and it passes. So you run some logic on this, but further down the line you need to apply some logic if the MC happens to be a RC. The cast can be true, because RC is a subclass of MC. The cast doesn’t HAVE to be true because not all MCs are RC. But indeed, if the unknown class isn’t an instance of RC the cast will fail. If the class is an instance of RC, it will also be an instance of MC. So you should be able to cast an MC instance to RC.

"While this is possible to cast a MC type to HC, I believe his mistake is in making the cast from the parent BP. I don’t know why you would do this in this way. "

"While this is possible to cast a MC type to HC, I believe his mistake is in making the cast from the parent BP. I don’t know why you would do this in this way. "

His implementation is wrong , he can’t cast self from parent class to HC.

You know, it’s not like I couldn’t see your name in that save error- sorry about that.

Actually I just tested this in a blank project and inheritance wasn’t our project’s problem. I added a parent, middle generation, and child BP (all BP with the superclass being actor of course). No errors at any point. Not fully sure why I was encountering the issue, but I’ve eliminated some error with inheritance and BPs.

Thanks guys - yeah you’re right I had a derp moment; I fixed it by taking away the cast I seem to remember. I was undermining the whole reason of having inheritance in the first place, as every instance of the child class was also technically an instance of the master so no need to cast. I couldn’t, however, fix the “can’t save” error so I ended up giving u the whole thing altogether. Also, I’m a “her” not a “him” :slight_smile:

Yeah you’re absolutely right - parent is a C++ camera character which inherits from ACharacter. Fixed it by removing the cast I seem to remember.

Haha no worries; thanks for the help!

I have had to migrate so many of my projects to a new projects because of unexplained errors.