I have found this piece of code showing how to call a blueprint function from C++:

 UFUnction* Func = Obj->GetClass()->FindFunction(FName("FuncName"));
 if(Func == nullptr){return;}
 FStructOnScope FuncParam(Func);
 UProperty* ReturnProp = nullptr;
 for (TFieldIterator<UProperty> It(Func); It; ++It)
     UProperty* Prop = *It;
     if (Prop->HasAnyPropertyFlags(CPF_ReturnParm))
         ReturnProp = Prop;
         //FillParam here            
 Obj->ProcessEvent(Func, FuncParam.GetStructMemory());

But… I don’t know how to //Fillparam here.

How can I fill the FuncParam with the parameters that I need to pass?

  • \$\begingroup\$ I can't think how to do this but I'm also wondering why you'd want to. What BP function are you trying to call and why? \$\endgroup\$ – Stephen May 19 at 9:01
  • \$\begingroup\$ @Stephen I have create a HUD using UMG UserWidget. This Widget has two custom event to update the HUD (player and opponent score). I have also a AHUD C++ class where I have added to ViewPort this UMG UserWidget. \$\endgroup\$ – VansFannel May 19 at 10:05

From what you've said in your comments, you're going about this backwards.

By default, C++ can't read Blueprint and, getting it do so seems like a very complicated way of doing it when there are much easier ways to go about this.

As the Widget is being derived from a C++ class, the easiest way for what you're trying to do would be to make a function in C++ but make it a UFUNCTION.

UFUNCTION(BlueprintCallable, Category = "Gameplay")
int32 GetPlayerScore();

Then in your CPP file, return an int32 showing the score. In your BP, you can now call this function directly and plug the output node into the necessary variable on your widget BP.

  • \$\begingroup\$ Thanks for your answer but I don't know how to make an UMG widget (a UserWidget, I think) derive from a C++, because when I'm going to create it (Mouse Right Click -> User Interface -> Widget Blueprint), I can't select any parent class. \$\endgroup\$ – VansFannel May 19 at 13:17
  • \$\begingroup\$ When do I have to call GetPlayerScore? On every tick? It's like doing pooling. Instead of calling a function from Blueprint, I think it is better to have a function in C++ that can be called when someone scores. How can I do that? Thanks. \$\endgroup\$ – VansFannel May 19 at 15:38
  • \$\begingroup\$ When creating your blueprint widget, don't go to User Interface -> Widget Blueprint, select the All Classes option instead. You can then search for your custom C++ class. If you've already created the blueprint class, you can reparent it by going to the Class Settings tab of the Blueprint and choosing your existing C++ class. \$\endgroup\$ – Stephen May 19 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.