Closed jrgalim closed 6 years ago
You are right, I'll add it to the wiki once we merge ue4.16 to master. To answer your question, though, it depends on the type of delegate. Dynamic delegates need using unreal.CoreAPI;
to be set, and then you can do either AddDynamic(obj.someUFunction)
. or BindDynamic(obj.someUFunction)
(depending if the delegate is multicast or not)
On non-dynamic delegates, you have a few options:
BindLambda(function() ..)
/ AddLambda(function() ...)
to add a haxe function. This function will always be called unless you explicitly remove the delegate afterwardsBindUFunction(obj.someUFunction)
/ AddUFunction
: adds a ufunction that is associated with a UObject-derived class. This needs using unreal.CoreAPI
as wellWe also have BindUObject
/ AddUObject
but that works just like the UFunction counterparts and rely on MethodPointer, which is only available for statically compiled (non-cppia) code, so this will probably be taken off for the release
Thank you for the thorough explanation! Very informative. Does the function that's being referenced require @uexpose
or anything? I tested it on a collision component, and I'm not getting any compile errors, but my function is also not being called:
CollisionComp.OnComponentHit.AddDynamic(this.OnHit); ... public function OnHit(HitComp:UPrimitiveComponent, OtherActor:AActor, OtherComp:UPrimitiveComponent, NormalImpulse:FVector, FHitResultHit:FHitResult) { trace("projectile hit something"); }
Like in Unreal, only ufunctions can be added to dynamic delegates. I'll make sure to add a check about this as well
Ah, yeah, that was the key, everything is working now. Thank you!
Wiki was updated
The wiki has an article on declaring delegates, but then how would I assign a function to the new delegate? Or an existing one?