How do i run a Console Command in C++

Exec() takes in parameter a const TCHAR*. But, TEXT(SomeString) does not perform FString conversion to const TCHAR*. To do this, you have to use the * operator. So, try this instead:

GetWorld()->Exec(GetWorld(), *Final);

TEXT(“some text”) should only be used to make a const TCHAR* for litterals (i.e. defining a string with quotes). Final is a FString, not a litteral. At a lower level, TEXT() adds a L before the litteral, to tell the compiler that the string is in wide char, as described in this page. Example: TEXT(“UE4”) will become L"UE4".

1 Like