proletariatgames / unreal.hx

Unreal.hx: Haxe Integration for Unreal
MIT License
424 stars 43 forks source link

Wiki - Assign Delegate? #71

Closed jrgalim closed 6 years ago

jrgalim commented 7 years ago

The wiki has an article on declaring delegates, but then how would I assign a function to the new delegate? Or an existing one?

waneck commented 7 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:

We 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

jrgalim commented 7 years ago

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"); }

waneck commented 7 years ago

Like in Unreal, only ufunctions can be added to dynamic delegates. I'll make sure to add a check about this as well

jrgalim commented 7 years ago

Ah, yeah, that was the key, everything is working now. Thank you!

waneck commented 6 years ago

Wiki was updated