CrashOrAssert - Returning a dynamic multicast delegate reference

Hi,

i am trying to expose some internal dynamic delegates with blueprint callable functions. However i run into a compile error like this:

Error : Failed to generate code for TestEditor - error code: CrashOrAssert (3)

A simple Sample code that reproduces this error:

UCLASS()
class TEST_API ATestClass: public AActor
{
    DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMyDelegate, int32, index);

    GENERATED_BODY()

public:
    UFUNCTION(BlueprintCallable, Category = "Test")
    FMyDelegate& GetTheDelegate();

    FMyDelegate MyDelegate;
};

ATestClass::FMyDelegate& ATestClass::GetTheDelegate()
{
    return MyDelegate;
}

It works fine with normal dynamic delegates ( not multicast).

In this simple example i could obviously just mark the delegate variable with UPROPERTY, but in my case that is no option because i need some logic to find the correct delegate based on different conditions.

Anyone has an idea how to overcome this error?

Recently I have investigated a bit what’s the problem because I need the same functionality.

The compiler says:

LowLevelFatalError [File:[...]\Runtime\CoreUObject\Public\UObject\UnrealType.h] [Line: 129]
Pure virtual not implemented (UProperty::GetCPPTypeForwardDeclaration)

when you declare such UFUNCTION. UMulticastDelegateProperty (derived from UProperty) does not contain implementation GetCPPTypeForwardDeclaration (used by UHT when parsing UFUNCTION code) which results an UHT crash.

That’s not the last problem. Using multicast dynamic as a function parameter also crash UHT. An interesting thing occurs when we cut off dynamic macro, it will not crash but say it’s unrecognized. This same problem leads to your’s GetTheEvent() when delegate is not dynamic. It would give us possibility to make a callback

About the direct answer to your question: Yes, there is a way - I it did using UPROPERTY in custom struct (I hate this workaround). See this:

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnExecuteEvent, ABaseCharacter*, Character);

UCLASS() //Absolutly NOT an USTRUCT, weird things in blueprint incoming
struct UEventContainer {
    GENERATED_USTRUCT_BODY()

    UPROPERTY(BlueprintAssignable, Category = "Event")
    UOnExecuteEvent Event;
};

[...] IAction //Yes, an Unreal Interface, that's crazy
UFUNCTION(BlueprintCallable, Category = "Event")
virtual UEventContainer* GetExecuteEvent() = 0;

Did it work? Yes but there was massive problems (ONLY when you use USTRUCT). Breaking the struct gave my pin with Event Dispatcher variable (brown, not red). The only thing I could do with was creating a variable (Event Dispatcher). This variable was very interesting - [there is no][1] way AT ALL to delete it and you can change its name only in pin. No problems if you use UCLASS. I can bind it anyway.
BTW tested in AnimBlueprint. Here is an image:

I’m not sure it will work when we implement it by ourselves and compile the engine.

It would be awesome if someone from UE stuff could take care of this.

I have just seen that JIRA is available now. Can you post this issue into it?