BpFunctionLibrary Add Actor Component to Target

Hello UE community. Probably noob question, that was already discussed, but I’m done googling and trying/compiling on slow laptop. So, hoping for your help. Thanks in advance!
So, I want Blueprint Function Library, actually containing only 1 function, to add Actor Components (not Scene Components) to Target’s Actor. But when I call this function UE just crashes. So, what am I doing wrong? Thanks!

h: Google Drive: Sign-in

cpp: Google Drive: Sign-in

As a rule of thumb you should always check for pointers to be valid. At the start of the function I would do something like this:

if(!IsValid(Component) || !IsValid(ToAdd))
{
    // Here you can also print an error to the log or handle the failure in some specific way
    return;
}

I would also check for valid reference after calling NewObject, so:

if(IsValid(newC))
    newC->RegisterComponent();

Thanks for help! Don’t know why I didn’t do all this checking before…I strongly believed the problem is in creating component via NewObject. Anyways, the solution was pretty easy and silly. I just put in wrong component type in Blueprints, where i was testing it q_q

Glad it helped :slight_smile: