Delegate Binding when BP inherits C++ Class

So, I’ve been wanting to slap myself in the face quite a few times lately. I’ll create a C++ class first, set up components as properties, allow the BP editor to see it, and when I do things like delegating events in the constructor of the actor, sometimes it works, and sometimes it doesn’t. It drives me crazy.

After research, I found out that UE serializes constructors when using BP’s that inherit the class, so adding the delegate binding after the fact won’t work since it doesn’t get updated. Shucks.

I found more info at this link:

https://forums.unrealengine.com/development-discussion/c-gameplay-programming/12970-beginplay-vs-constructor

One of the comments in that thread says, “constructor is good for default, component initiation and delegate binding.”

But is that statement true if it works only if you bind it before creating the blueprint? It sucks to have to delete blueprints and re-create it. Is there a way to “refresh” or “reserealize” ? Or should delegate binding be defined on “PostInitializeComponents” or “BeginPlay”?

What way is preferred? I typically only see this in the constructor and sometimes in BeginPlay. What’s the community’s consensus?

Thanks for your help in advance!

I do all of my delegate binding in BeginPlay and have no issues.

For those that stumble on this particular problem and no solution, also try to do a total re-generation of your project files. This solved it for me.

Delete the Binaries, Intermediate, DerivedDataCache and Saved directories.

Rightclick your Unreal Engine Project file and “Generate Visual Studio Files”

Build entire solution, and it worked for me.

========

Side note, I think the problem stems from creating a BP derived from a c++ class that doesn’t have delegates first. Then after that adding delegates. Compiler and editor sees this as okay but the BP you first created seems to not be “refreshed”

To verify, create a totally different BP from the class (now with delegates) and assuming no other errors, the delegate should fire…hence my theory that BP isn’t “refreshing” and why a total project regeneration should trigger the “refresh”.

gl