C++ Interface Type not available for casting in Blueprint

Hi,
I have a C++ Interface which forces the implementing Actor to have a simple Function: GetSomeComponent (in this case a component representing a resource like Health or Mana). This function needs to be available in Blueprints so it specifies UFUNCTION(BlueprintCallable).

In order to be aBlueprintCallable function the interface specifier needs to be NotBlueprintable

And to be able to check in Blueprints that an Actor inplements the interface the specifier BlueprintType.

The interface looks like this:

UINTERFACE(MinimalAPI, BlueprintType, NotBlueprintable)
class UHealthInterface : public UInterface
{
	GENERATED_BODY()
};

/**
 * Force the implementing class to have / return a Resource Component representing Health.
 */
class GAME_API IHealthInterface
{
	GENERATED_BODY()

public:
        UFUNCTION(BlueprintCallable)
	virtual class UResourceComponent* GetHealthResourceComponent() const = 0;
};

So far so good. But the issue is, I can’t cast the Actor to the HealthInterface type in blueprints, it’s not showing up. In the following example I try to cast in in a Widget Blueprint:

So now comes the weirdest part:
I solved the problem somehow by doing the following:

  1. removing the interface specifier NotBlueprintable as well as the function specifier BlueprintCallable
  2. compile the project
  3. now I was able to get the type cast node:
  4. problem is now that I can’t (as required) to call GetHealthResourceComponent() from blueprints
  5. I kept the type cast node in blueprints went back to C++ and added back NotBlueprintable and BlueprintCallableand compiled
  6. went back to blueprints and now I can call the function as wanted from the interface:
    interface cast and function call

My question is, is the thing I want to do valid and it is this an unreal bug if BlueprintType and NotBlueprintable is used together that the type cast does not show in blueprints?

Or did I just do an evil hack which is not intended to work and falls upon my feet later?

1 Like

Was able to solve it by changing the order of the UINTERFACE specifiers.
By using UINTERFACE(NotBlueprintable, BlueprintType) instead of UINTERFACE(BlueprintType, NotBlueprintable).

So while using NotBlueprintable and BlueprintType together there order must be this way for the type cast showing up in blueprints.

Tested this for UE 5.0 and 5.1.

3 Likes

This appears to work as well, UE5.3.2: