Download

About the wiki "Delegates in UE4, Raw C++, and BP Exposed"

A question about this wiki:

I try to use the “built in” signature OnComponentBeginOverlap, but can’t manage to bind a function in another class than the class where the overlap is detected. Is this a limitation in the “built in” signatures? I take it it is a way of making some common situations (things overlapping e.g) very easy to handle by letting it trigger a function call without the need to explicitly call Broadcast()?

Binding seems to be done in any class in Rama’s wiki, but I don’t get how I can get the hold of an OBJECT of the class where the delegate signature is defined like RamaMeleeWeaponComp:

“RamaMeleeWeaponComp->RamaMeleeWeapon_OnHit.AddDynamic(this,&USomeClass::RespondToMeleeDamageTaken);”

I have followed a tutorial (https://unrealcpp.com/light-switch-trigger/) and then I go:

LightSphere->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchTrigger::OnOverlapBegin);

to trigger a function call in the same class, but how to do the same in e.g the main character?

Best regards
Ulf

In hindsight, I think what I missed was that an instantiated OBJECT is needed to contain the delegate definition. I thought I could do it so that any spawned actor defining the delegate signature and any other spawned actor with a function to trigger could be bound to each other when spawning (every time they are set loose into the world), but that is probably not possible?

Yes, you need an instance of an object to bind any of its functions to a delegate.
Also, keep in mind that the collision delegates are sparse - binding a lot of objects to it is costly.

1 Like