Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log a message from a string variable in Unreal Engine?

I am trying to log a message form a string variable , below is the code I used

std::string s = "ss";//std::to_string(FPaths::GetPath("../"));
 UE_LOG(LogTemp, Warning, *s);

but it's not working, Can someone tell me how to do this ? enter image description here

like image 529
Kas Avatar asked Jul 21 '16 09:07

Kas


2 Answers

Finally I am answering my own question here.

It doesn't compile because I need to use the TEXT Macro before giving a string into UE_LOG.

FString s = "ss";
 UE_LOG(LogTemp, Warning, TEXT("%s"), *s);

 //or

 UE_LOG(LogTemp, Warning, TEXT("ss"));

 //this should work
 UE_LOG(LogTemp, Warning, TEXT("%s"), *FPaths::GetPath("../"));

should work with Unreal's version of Datatypes instead of using the std library

like image 97
Kas Avatar answered Nov 06 '22 20:11

Kas


If you really have to than you can convert std::string to FString and than log that like this.

std::string someString = "Hello!";
FString layerName(someString .c_str());
UE_LOG(LogTemp, Warning, TEXT("%s"), *layerName);
like image 43
Mohit Pundir Avatar answered Nov 06 '22 18:11

Mohit Pundir