Inconsistent Construct Widget BP Compiling Behavior when using Class Variables between Runtime and Commandlet/Cooker

Image can explain this a lot better than words.

I have 3 Widget Blueprint classes. WB_HUD_Base, WB_HUD_Desktop, WB_HUD_Mobile. Desktop and Mobile classes are both children of WB_HUD_Base.

HUDWidget, MobileHUDClass, and DesktopHUDClass are set to type WB_HUD_Base / class of type WB_HUD_Base.

The Construct Widget nodes are correctly returning widgets of type WB_HUD_Base and at runtime/editor compiling, this type information is preserved and setting HUDWidget works great and everything is fine and dandy. When cooking though, the Construct Widget return value has a type of UserWidget, which then causes an error as you can’t assign a UserWidget to a variable of type WB_HUD_Base.

The workaround is currently to do a ‘redundant’ cast, which results in an runtime/editor warning but allows the cooker and other commandlets to cook and work correctly.

I tried using a “Select Class” node to simplify the number of nodes needed here but that only caused a butt load of more issues; in any case, this should work. I don’t really have a preference if a cast here is needed or not, but its need needs to be consistent across runtime/editor/cooking.

Hello ,

I was unable to reproduce this issue on our end. I have a few questions for you that will help narrow down what issue it is that you are experiencing.

Quick questions:

  1. Can you reproduce this issue in a clean project?
  2. If so, could you provide a detailed list of steps to reproduce this issue on our end?
  3. I noticed that you said that you receive an error with out the cast, could you provide the error that is given?

I was able to reproduce this in a clean project, however doing so I found a fix. The issue arises when the Create Widget node has a literal class assignment (using the drop down, no variable) of the more specific child class instead of the base class, and then is assigned a variable with type of the base class. This fails to update the Construct node, causing these issues. In small projects the editor seems to update this and then create consistent behavior by flagging BP_HUD as not able to be compiled due to type mismatch… In larger blueprint graphs it seems to fix this silently in the editor but the cooker doesn’t get the fix. I’m not sure why this is, but I’ve set this graph up in a new project and a separate bigger project which wasn’t the original project of this bug, and am getting this differing behavior. The difference could be that the bigger projects have been around since 4.5 or earlier, and there might be some residual effects of some blueprint node changes?

Fix for this is to unlink the class variable assignment and set the class to the base type, then assign using the variable of the same type. This makes it so the Construct widget isn’t in a wrong state and won’t require any fixing up.

Fix for this is to unlink the class variable assignment and set the class to the base type, then assign using the variable of the same type. This makes it so the Construct widget isn’t in a wrong state and won’t require any fixing up.