1
0

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 1 year has passed since last update.

[Unity] The referenced script (Unknown) on this Behaviour is missing! の対策

Posted at

The referenced script (Unknown) on this Behaviour is missing!
The referenced script on this Behaviour (Game Object 'hoge') is missing!

というような警告が表示された際に、問題となっている GameObject を抽出する方法です。

① 下記スクリプトをプロジェクトに配置

MissingComponent.cs
using UnityEditor;
using UnityEngine;

public class MissingComponent {
	[MenuItem("Tools/Find Missing Components")]
	public static void Find() {
		Debug.Log("Start Find Missing Components.");
		bool isFind = false;
		GameObject[] instances = Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[];
		foreach (var instance in instances) {
			int count = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(instance);
			if (count > 0) {
				Debug.LogError("Failed!! Find Missing Component in Scene. name=" + instance.gameObject.name);
				isFind = true;
			}
		}
		string[] prefabGUIDs = AssetDatabase.FindAssets("t:prefab");
		foreach (var prefabGUID in prefabGUIDs) {
			string path = AssetDatabase.GUIDToAssetPath(prefabGUID);
			GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
			int count = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(prefab);
			if (count > 0) {
				Debug.LogError("Failed!! Find Missing Component in Prefab. name=" + prefab.gameObject.name);
				isFind = true;
			}
		}
		if (isFind == false) {
			Debug.Log("Success!! Not found missing components.");
		}
	}
}

② UnityEditor のメニューから、Tools/FindMissingComponents を押す

Missing なコンポーネントを含んだ GameObject の名前が Console に出力されるので、
それをヒントに当該 GameObject から Missing を Remove するなどの適切な対応をとる。

1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?