Interfaces & Inheritance

After using UE4 for a while I have some thoughts on the balance between C++ and blueprints.

  • Is it possible to create a C++ interface and then implement that into a blueprint class? Whenever I create a C++ interface the interface list in the blueprint never shows my C++ interface.

  • Wouldn’t it be cool if you could do something like this:

  • BaseClass (C++)
    - bpBaseClass (Blueprint)

    • ChildClass (C++)
      - bpChildClass (Blueprint)
      • ThirdChildClass (C++)
        - bpThirdChildClass (Blueprint)

So the ThirdChildClass inherits from ChildClass but also picks up all the features of the blueprint extensions along the way without referencing them, it would mean C++ and blueprints would be almost a reflection of each other just with the option to add blueprint functionality at run time.

Currently you can’t do this because the C++ classes need to know their parent class at compile time, but perhaps there is a way to treat blueprints as more an extension of a class as opposed to a whole new class unto itself?

Thanks

C++ cannot inherit from Blueprints. The reason is that Blueprints are runtime data, and can be changed at runtime – but C++ needs to compile to bake in the information about the base class. This is why inheritance in C++ is reasonably low cost and fast, whereas inheritance in more dynamic languages (Smalltalk, Blueprints, etc) is more expensive and slower.

You can achieve something similar by creating interfaces that each of your steps in the ladder implement, and then use delegation, rather than inheritance, for the cross-language composition. In general, delegation is better design than inheritance anyway, because inheritance confuses two things – the public behavior of some interface, and the specific implementation details of some class. Anything you do further down in the inheritance hierarchy will suddenly impose invisible constraints on the higher-up classes, because some change higher-up may break something further-down.