Interfaces passing Interfaces?

I haver two interfaces, a Manager and a Worker. I can’t seem to find the correct syntax. I want to pass a generic Worker to a generic Manager.

#pragma once

#include “Worker.h”
#include “Manager.generated.h”

class UManager : public UInterface

class MYCLASS_API IManager


UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Interaction")
	bool DeliverWorker([something] worker);


I have tried TScriptInterface<IWorker> const& in place of [something], which sort of works, but not if I want to assign it to an internal IWorker pointer. I have also tried IWorker *. Is there a protocol for passing a pointer to an interface inside a function call (in anoppther interface). I have done this in blueprints, but no luck so far in C++.



First, did you declare the IWorker interface?

class IWorker

	void SomeFunction(); // The abstract interface method

As for creating functions that take IWorker as parameters, AFAIK this is a limitation of the UnrealHeaderTool: it doesn’t generate the proper code to handle TScriptInterface arguments, so you need to do it manually like this:

UFUNCTION(BlueprintNativeEvent, BlueprintCallable, CustomThunk, Category = "Interaction")
bool DeliverWorker(TScriptInterface<IWorker> worker);
	P_GET_TINTERFACE(IWorker, Z_Param_Worker);
	*(bool*)Z_Param__Result = IManager::DeliverWorker(Z_Param_Worker);

I don’t know if this changed in 4.14.

I have a further question. I am trying to pass a pointer to the function. It is a pointer to a class that implements the interface, and I am getting an “error C2440: ‘initializing’: cannot convert from ‘ClassName *’ to ‘IInterfaceName *’” Is there any way around this. The UnrealHeaderTool also didn’t like when I used “TScriptInterface<IWorker> worker” instead of “TScriptInterface<IWorker> const& worker”

Thanks in advance.

Hi, did you find the workaround for this? I am trying to use interfaces as the function parameters and return types, but it can work only with const references which is not what I want to get.