I have an interface that I created by following the guide lines of the Interface article on the wiki called IInteractableActorInterface.
https://wiki.unrealengine.com/Interfaces_in_C%2B%2B
I have a Pawn that holds a pointer that references a IInteractableActorInterface that they are currently looking at and when you press E something happends. However for the life of me I get a compile time error that makes no bloody sense.
/**
* Class required to support Interface Casting within the Unreal Engine System.
*/
UINTERFACE(MinimalAPI)
class UInteractableActorInterface : public UInterface
{
GENERATED_UINTERFACE_BODY()
};
/**
* InteractableActorInterface is an interface implemented by all objects within the game world
* that can be interacted with by a Pawn and Player.
*/
class IInteractableActorInterface
{
GENERATED_IINTERFACE_BODY()
/**
* Performs interaction on the object and supplies the instigator who triggered the action.
*/
virtual void Interact(APawn * instigator) = 0;
/**
* Sets the proper properties for the instigator to alert the player or AI
* that the item is available for interaction.
*/
virtual void PrepareInteraction(APawn * instigator) = 0;
/**
* Get a string that displays the interaction message.
*/
virtual FText GetInteractionMessage() = 0;
};
class AMyCharacter
{
// standard stuff here
private:
IInteractableActorInterface * interactableActor;
public:
IInteractableActorInterface * GetInteractableActor();
void SetInteractableActor(IInteractableActorInterface * interactableActor);
};
Error 7 error C2664: ‘void
FScriptInterface::SetObject(UObject
*)’ : cannot convert argument 1 from ‘IInteractableActorInterface *’ to
'UObject
*'InteractableActorInterface.cpp C:\Program
Files\Unreal
Engine\4.4\Engine\Source\Runtime\CoreUObject\Public\UObject\ScriptInterface.h 144 1
Now this error ONLY occurs if I use a pointer of the type of the interface, if I switch it to a hard coded type all is peachy…
class AMyCharacter
{
// standard stuff here
private:
APickup * interactableActor;
public:
APickup * GetInteractableActor();
void SetInteractableActor(APickup * interactableActor);
}
I have even commented out any locations where a InterfaceCast(object) is performed and still I get this error.
Digging through the Output I find:
C:\Program Files\Unreal Engine\4.4\Engine\Source\Runtime\CoreUObject\Public\UObject\ScriptInterface.h(144): error C2664: 'void FScriptInterface::SetObject(UObject *)' : cannot convert argument 1 from 'IInteractableActorInterface *' to 'UObject *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1> F:\Projects\UE4\Vishnu\Source\MyGame\Classes\Player\MyGameCharacter.h(16) : see reference to function template instantiation 'InterfaceType &TScriptInterface<InterfaceType>::operator =<IInteractableActorInterface>(UObjectType *)' being compiled
1> with
1> [
1> InterfaceType=IInteractableActorInterface
1> , UObjectType=IInteractableActorInterface
1> ]
1> F:\Projects\UE4\Game\Source\MyGame\Classes\Player\MyGameCharacter.h(16) : see reference to function template instantiation 'InterfaceType &TScriptInterface<InterfaceType>::operator =<IInteractableActorInterface>(UObjectType *)' being compiled
1> with
1> [
1> InterfaceType=IInteractableActorInterface
1> , UObjectType=IInteractableActorInterface
1> ]
I don’t think I need to say it… but having to use a hard coded type defeats the purpose of trying to use an interface… any suggestions on what this error means would be highly welcome…
EDIT:
Clarification of Subject header… wrote this late at night and was tired.