For future users here is the C++ code i used. Since I already had a custom C++ Blueprint Function Library all i had to do was add this new node into that. But for new users you can follow this tutorial on how to add custom Blueprint node.
Header file:
UFUNCTION(BlueprintCallable, Category = "MyCustomCategory")
static void SetNewOwner(AActor* NewOwner, AActor* Weapon);
Source file:
void USplashivBPLibrary::SetNewOwner(AActor* NewOwner, AActor* Weapon)
{
if (!NewOwner == NULL && !Weapon == NULL)
{
Weapon->SetOwner(NewOwner);
}
}