In my current project, I’m converting some blueprints into C++.
One of these blueprints is able to search through all actors within the current scene, and return the interface for the first valid object which utilizes said interface:
https://forums.unrealengine.com/attachment.php?attachmentid=57682&d=1442544455
As you can see, returning an interface works just fine in blueprints. In C++, however, I’ve tried several different ways to return an interface, and can’t get any of them to compile.
Here’s some of the following setups (and their corresponding errors) that I’ve tried:
-
IMarionettistInterface *FindMarionettistInScene(TEnumAsByte MarionettistName, bool &Error);
ScriptInterface.h(144): error C2664: ‘void FScriptInterface::SetObject(UObject *)’ : cannot convert argument 1 from ‘IMarionettistInterface *’ to ‘UObject *’
MarionettistUtilities.h(8) : see reference to function template instantiation ‘InterfaceType &TScriptInterface::operator =(UObjectType *)’ being compiled with… -
UMarionettistInterface *FindMarionettistInScene(TEnumAsByte MarionettistName, bool &Error);
ScriptInterface.h(146): error C2440: ‘initializing’ : cannot convert from ‘UMarionettistInterface *’ to ‘IMarionettistInterface *’
MarionettistUtilities.h(8) : see reference to function template instantiation ‘InterfaceType &TScriptInterface::operator =(UObjectType *)’ being compiled with… -
void FindMarionettistInScene(TEnumAsByte MarionettistName, bool &Error, IMarionettistInterface *Interface);
MarionettistUtilities.h(8): error C2664: ‘void UMarionettistUtilities::FindMarionettistInScene(TEnumAsByte,bool &,IMarionettistInterface *)’ : cannot convert argument 3 from ‘TScriptInterface’ to 'IMarionettistInterface *
-
void FindMarionettistInScene(TEnumAsByte MarionettistName, bool &Error, UMarionettistInterface *Interface);
MarionettistUtilities.h(8): error C2664: ‘void UMarionettistUtilities::FindMarionettistInScene(TEnumAsByte,bool &,UMarionettistInterface *)’ : cannot convert argument 3 from ‘TScriptInterface’ to ‘UMarionettistInterface *’
-
void FindMarionettistInScene(TEnumAsByte MarionettistName, bool &Error, const IMarionettistInterface &Interface);
MarionettistUtilities.h(12) : Missing ‘*’ in Expected a pointer type
… Anyhow, I’m sure you get the idea. I’m a bit stumped how this is actually done.
Oh, and in case you’re interested, line #8 of MarionettistUtilities.h
is GENERATED_UCLASS_BODY()
, and line #12 is the above function I’m trying to compile (currently, it’s the only one in the class).
So what is the correct way to convert this blueprint into C++?