Heya!
I’m trying to turn this thingy into c++:
Basically, bind events in c++…
https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/EventDispatcher/BindingAndUnbinding/index.html
I’ve been finding stuff on delegates, but I’m not sure how they work, and if they can be unbound/bound during runtime.
Thanks!
EDIT: Found the answer, look at post below
2 Likes
Alright, I got it working!!
First, I create a TScriptDelegate object:
TScriptDelegate <FWeakObjectPtr> EquipFinished;
I then bind the function that I want to run:
EquipFinished.BindUFunction(this, "EquipAnimationComplete");
And then add it to the event!
MyPawn->GetMesh()->GetAnimInstance()->OnMontageBlendingOut.Add(EquipFinished);
And whenever I want to remove it, I just do this:
MyPawn->GetMesh()->GetAnimInstance()->OnMontageBlendingOut.Remove(EquipFinished);
It’s GLORIOUS! xD
7 Likes
zaha
(zaha)
July 25, 2015, 7:41am
3
Hey,
glad you figured it out.
There are also some resources in the Wiki on event handling:
Event handling
Simple Global Event System
and of course the documentation page about binding delegates:
Binding delegates
Not sure what the TScriptDelegate is exactly, it’s not in the examples. I guess it’s a wrapper type for the callback function required by dynamic delegates. (I only used normal delegates until now)
Fieol
(Fieol)
January 10, 2020, 12:42pm
4
anonymous_user_a4d67e591:
Alright, I got it working!!
First, I create a TScriptDelegate object:
TScriptDelegate <FWeakObjectPtr> EquipFinished;
I then bind the function that I want to run:
EquipFinished.BindUFunction(this, "EquipAnimationComplete");
And then add it to the event!
MyPawn->GetMesh()->GetAnimInstance()->OnMontageBlendingOut.Add(EquipFinished);
And whenever I want to remove it, I just do this:
MyPawn->GetMesh()->GetAnimInstance()->OnMontageBlendingOut.Remove(EquipFinished);
It’s GLORIOUS! xD
How do you give value inside
TScriptDelegate <FWeakObjectPtr> EquipFinished;
?