Skip to content

Logging inside C++ code

Here is an example of how to use Debug.Log in C++ code:

#include <unityengine.h>

void LogMessage()
{
    DebugLog("Hello from C++!");
    DebugWarning("This is a warning message.");
    DebugError("This is an error message.");
}

You can also use Debug.Log to log formatted messages using std::to_string or other string formatting functions. Here is an example of logging a formatted message in C++ code:

#include <unityengine.h>
#include <string>

void LogFormattedMessage()
{
    DebugLog("Hello from C++! " + std::to_string(42));
}