Invoke Blueprint Delegate

I have a blueprint callable method which receives two dynamic delegates.

The method is a standard BlueprintCallable:

UCLASS()
class AOuyaSDK : public AActor
{
	GENERATED_UCLASS_BODY()

	///
	/// ADD INIT OUYA PLUGIN VALUES
	///

	// success callback
	DECLARE_DYNAMIC_DELEGATE(FDelegateOnSuccessAddInitOuyaPluginValues);
	FDelegateOnSuccessAddInitOuyaPluginValues OnSuccessAddInitOuyaPluginValues;

	// failure callback - int32 errorCode, FText errorMessage
	DECLARE_DYNAMIC_DELEGATE_TwoParams(FDelegateOnFailureAddInitOuyaPluginValues, int32, errorCode, FString, errorMessage);
	FDelegateOnFailureAddInitOuyaPluginValues OnFailureAddInitOuyaPluginValues;

	// Add Values to use in InitOuyaPlugin
	UFUNCTION(BlueprintCallable, Category = OUYA)
	void AddInitOuyaPluginValues(FString key, FString value, FDelegateOnSuccessAddInitOuyaPluginValues onSuccess, FDelegateOnFailureAddInitOuyaPluginValues onFailure);

};

In the event implementation, I’m trying to invoke the onSuccess delegate and nothing happens. The onSuccess delegate should have been passed as a parameter for the event.

void AOuyaSDK::AddInitOuyaPluginValues(FString key, FString value, FDelegateOnSuccessAddInitOuyaPluginValues onSuccess, FDelegateOnFailureAddInitOuyaPluginValues onFailure)
{
	OnSuccessAddInitOuyaPluginValues = onSuccess;
	OnFailureAddInitOuyaPluginValues = onFailure;
#if PLATFORM_ANDROID
	__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "AddInitOuyaPluginValues");
	std::string sKey = TCHAR_TO_ANSI(*key);
	std::string sVal = TCHAR_TO_ANSI(*value);
	_initPluginValues[sKey] = sVal;
	if (OnSuccessAddInitOuyaPluginValues.IsBound())
	{
		__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "OnSuccessAddInitOuyaPluginValues is bound");
		OnSuccessAddInitOuyaPluginValues.Execute();
	}
	else
	{
		__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "OnSuccessAddInitOuyaPluginValues is not bound");
	}
#endif
}

This is the most simple delegate since it has no parameters for onSuccess.

The documentation says it needs to be bound.

Do you still need to bind something to invoke the method when it was passed to you as an argument?

If you look at the image I’m expecting when I invoke onSuccess that the onSuccessAddInitOuyaPluginValues custom event will fire based on the way I used the custom event as a delegate in the event parameters.

Also “AddInitOuyaPluginValues” is being logged so I know the code is being executed.

Also checking if onSuccess Delegate is bound returns true.

V/OuyaSDK (15078): AddInitOuyaPluginValues
V/OuyaSDK (15078): OnSuccessAddInitOuyaPluginValues is bound

If the delegate is Bound, calling Execute should invoke the Custom Event right?

The expected result should have been the Custom Event was invoked and the Status text should be set to “AddInitOuyaPluginValues SUCCESS”.

The observed behaviour is the status text remains: “Status: Adding Init OUYA Plugin Values…”.

And that only happens a single time before the “AddInitOuyaPluginValues” method is invoked.

Thoughts and insights are appreciated.

Thanks,

~Tim Graupmann

The expected delegate is being called.

I was invoking the method and immediately setting the text afterward, assuming the callbacks would happen sometime later.

When really (after debugging) the Delegate OnSuccessAddInitOuyaPluginValues was being invoked as expected, which set the text. Then , then the method AddInitOuyaPluginValues finished setting the text back to “Status: Adding Init OUYA Plugin Values…”.

So it just looked like it wasn’t being called.

I changed the order to set the text before invoking the AddInitOuyaPluginValues method and now everything is happening as expected.