Can you call a function depending on which number an integer is

I want to have

Function1

Function2

And call them depending on a variable

Maybe if the functions are in some sort of array

What is the best way to do this

you may get the function at generated files, and call it via

FString FuncName = “Function1”;
UFunction* const Func = UObjectPtr → FindFunction(FuncName);
if(Func)
Func ->ProcessEvent(Func);

if your function has some params, you’ll need to create a struct suit the params, and get values of params, then instead of ProcessEvent(Func), ProcessEvent(Func, &Params);

So to change the function it calls I change the FuncName string

Eg

 void ChangeStringFunc()
 {
      if (SOMETHING)
      {
           FString FuncName = "Function1"; 
      }
      else
      {
            FString FuncName = "Function2";
      }
 }

 void CharacterFunction()
 {
 UFunction* const Func = UObjectPtr -> FindFunction(FuncName);
 if(Func) Func ->ProcessEvent(Func);
 }

Hi,

This seems like a good use of a switch statement, look at the example below:

switch(myInteger) {
  case 1:
    Function1();
    break;
  case 2:
    Function2();
    break;
  default:
    // If no case exists for myInteger
    GEngine->AddOnScreenDebugMessage(-1,1.f, FColor::Blue, "switch failure");
}

Switch statements are more performant and preferred over an if/else statement, each case can include any amount of code you would like.

Kind Regards,