Download

Cant bind delegate in cpp

Hello guys !
Am making this post cause am having trouble understanding the right way to use delegates inside the engine (beginner here).
I created inside an actor a delegate which is called FGameStateSigleTODChanged and inside the same header file (but not the same class) this code:

In the actor header

to declare a method using the delegate

I use a broadcast inside the cpp file of the actor also

in the actor cpp file

Well so far so good. If I place an actor inside the level and that I bind my method to a custom event in BP, It works as expected.
The problem comes if I try to make it work in cpp using the same logic.
I try to get all the actor of my actor’s class. I cast my class to the resulting actor but can’t seem to be able to bind it (it’s not a proposed method)

code inside the other class cpp:

I hope I am clear enough and I am sure it’s just a rookie mistake.
Thanks a lot for taking the time to read me !

Tell me if I am not clear enough, am struggling to find a solution here :confused:

  1. Is the binding call meant to be outside of your null check?
  2. Where are you binding it? I found that sometimes binding stuff doesnt work unless you do it inside the overridden PostInitializeComponents()

Im not an expert at all but some stuff to think about, I had some similar problems at some point.

hey !

  1. Yup the binding call is outside the null check but that’s not really the problem here. The full code line that I am writting is not validated by intelisense in the first place
  2. Am binding it inside an actor component’s class. Thought I could bind from anywhere really. I also tried within an actor, didn’t seem to work either

Try AddDynamic macro instead of BindUObject