support lambda functions in delegates

I’m looking at timeline delegates and it would be nice to support lambda functions for delegates.

You can actually use lambdas already with UE4 delegates, as long as you don’t capture variables with your lambda. Here is an example from some Slate UI.

	.Image( FEditorStyle::GetBrush("EditorLiveStreaming.BroadcastButton") )
	.ColorAndOpacity_Static( ] 
		FSlateColor Color = FLinearColor( 1.0f, 1.0f, 1.0f, FMath::MakePulsatingValue( FSlateApplication::Get().GetCurrentTime(), 2.0f ) );
		return Color;
	} )

For timelines, you would use syntax like:

MyDelegate = FOnTimelineEvent::CreateStatic( ] { DoSomething(); } );

In 4.6 we will have support for stateful lambdas as well, by using the new “FMyDelegate::CreateLambda()” functions that we’ve added. Hope that helps!


good news ! thanks Mike :slight_smile:

lambda(lambda) :slight_smile:

Awesome! Thanks Mike!

In the upcoming Unreal Engine 4.6 we’ve added even better support for lambdas with delegates. You can use the new “CreateLambda” and “BindLambda” functions to bind your delegate to a lambda that captures local variables.


cool !

is this change in some 4.5 tag branches? or only in main branch?

Just in “master” branch on GitHub for now, which is the super-early version of UE 4.6. But you could manually merge the changes over to your branch if you really wanted to of course.