- Home /
Question by
integer_32 · Dec 05, 2021 at 05:11 PM ·
player
How to crash Unity Player on any error?
I'm using Unity for server-side video rendering, and it's very important for me to crash the player on any error.
I know that it's an intentional behaviour that Unity doesn't crash on exceptions, so I used a workaround that reads logs:
namespace Utils
{
public class LogHandler : MonoBehaviour
{
private void Awake()
{
Application.logMessageReceived += HandleException;
DontDestroyOnLoad(gameObject);
}
private static void HandleException(string logString, string stackTrace, LogType type)
{
if (type == LogType.Exception)
{
Debug.LogError($"Caught an exception: {logString}");
Debug.LogError($"Stack trace: {stackTrace}");
Util.Quit(1);
}
}
}
}
But it's not enough, in real life sometimes player stucks with some errors that don't lead to the crash.
Is there some another, more stable way to crash it on any exception?
Comment
Your answer
Follow this Question
Related Questions
Player names all displayed as local player 1 Answer
Clicking on object to teleport player? 1 Answer
Distance destroy object 3 Answers
How to put Networkview.isMine in mouselook 0 Answers
Control Player ignoring TimeScale. 2 Answers