Download

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.


	
SNew(SImage)
	.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!

–Mike

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. https://github.com/EpicGames/UnrealEngine/commit/1d84d219d2e5c3082d3d188c13050db5c18cd682

–Mike

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.

–Mike