11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

例外発生時にアプリを一時停止する

Posted at

エディタでアプリを実行している場合、例外が発生したらそこで実行を停止して欲しいので以下のようなスクリプトを書いた。

Autorun.cs
using UnityEngine;
using System.Collections;

/// <summary>
/// Editorでのスクリプト起動時に初期化処理を実行
/// </summary>
[UnityEditor.InitializeOnLoad]
public class Autorun : MonoBehaviour {
	static Autorun() {
		Debug.Log ("*** Debug.Log hooked by Autorun.LogCallbackHandler()");
		Application.RegisterLogCallback(LogCallbackHandler);
	}
	
	static void LogCallbackHandler(string condition, string stackTrace, LogType type) {
		if (type == LogType.Exception) {
           // Unity Editor 上で実行中の場合のみ実行を一時停止する
			if (UnityEditor.EditorApplication.isPlaying) {
				UnityEditor.EditorApplication.isPaused = true;
			}
		}
	}
}

参考: Uncaught exception doesn't kill the application - Unity Answers

11
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?