Is it possible to bind a function to a delegate without a pointer to the delegate owner? In every “tutorial” I follow the function is always bound using a pointer. For example, this works fine.
However, while browsing the engine code, I never see casting happen before a delegate is bound. Instead I see things like below, which appears to be binding without casting.
I’m curious if I am misunderstanding what is happening here, as trying to bind my own functions in the same manner as shown below, gives the following error: “‘SomeEvent’: is not a member of ‘SomeEventDelegate’”
It is possible to bind delegates to static members of a struct or a class (not relative to a specific object). Here i set up a test delegate to randomly change a color of a material.
First we setup our struct
as we declared a static member in a header file, we need to define it in a CPP file to avoid duplicated symbols, so put this line in any CPP file once
Then we can broadcast and bind functions to the delegate like you said.
I just got to test this out and it works perfectly. I want to thank you for taking the time to give such a detailed response. My problem it seems was that my events were not declared as static in a struct. I also tested this using events instead of a standard multicast delegate (I only need a single broadcaster in this case), and it works just as well. Again, I really appreciate your assistance. Have a great weekend.