Announcement

Collapse
No announcement yet.

[Bug Report] BlueprintImplementableEvent and Interfaces don't work together

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [Bug Report] BlueprintImplementableEvent and Interfaces don't work together

    Code:
    #pragma once
    #include "TargetInterface.generated.h"
    UINTERFACE(MinimalAPI)
    class UTargetInterface :
    	public UInterface
    {
    	GENERATED_UINTERFACE_BODY()
    };
    
    class ITargetInterface{
    	GENERATED_IINTERFACE_BODY()
    public:
            UFUNCTION(BlueprintImplementableEvent, meta=(FriendlyName = "On Interact"))
    	void OnInteract();
    }
    It compiles fine and I can access the event in my blueprints but it will always throw an error when I call OnInteract(). It works fine if I put the BlueprintImplementableEvent in a normal class.
    Last edited by maikklein; 04-11-2014, 03:04 PM.

    #2
    I think I had that problem too.
    I assume you do something like this?

    InterfaceOfMyActor= InterfaceCast<ITargetInterface>(Actor);
    InterfaceOfMyActor->OnInteract();

    Solution:
    For some reason you are not allowed to call the function directly if implemented via an interface.
    Instead do this (Note: First function argument is the Actor the Interface is casted from. Followed by all normal function args you want to send.):

    InterfaceOfMyActor= InterfaceCast<ITargetInterface>(Actor);
    InterfaceOfMyActor->ExecuteOnInteract(Actor);

    I don't know why you have to do it this way. But for me it works fine...

    Edit - correction:
    Forgot an underscore. It should be
    InterfaceOfMyActor->Execute_OnInteract(Actor);
    Last edited by jbjhjm; 04-12-2014, 05:46 AM.

    Comment


      #3
      Originally posted by jbjhjm View Post
      I think I had that problem too.
      I assume you do something like this?

      InterfaceOfMyActor= InterfaceCast<ITargetInterface>(Actor);
      InterfaceOfMyActor->OnInteract();

      Solution:
      For some reason you are not allowed to call the function directly if implemented via an interface.
      Instead do this (Note: First function argument is the Actor the Interface is casted from. Followed by all normal function args you want to send.):

      InterfaceOfMyActor= InterfaceCast<ITargetInterface>(Actor);
      InterfaceOfMyActor->ExecuteOnInteract(Actor);

      I don't know why you have to do it this way. But for me it works fine...
      Many thanks, that seems to work.

      Comment


        #4
        A quicker way of doing this, without the need for an explicit cast, is to use the static helper function we automatically generate with interfaces. In your example, assuming that your interface is called "ITargetInterface", you could simply call:

        ITargetInterface::Execute_MyFunction(Actor);

        which does the cast, and conditional call in one handy function!

        Comment

        Working...
        X