pgintro.net

Unity エラーと警告

作成日時:2019/01/16

更新日時:2019/06/28

スポンサーリンク

エラーと警告

改行コードが混在している場合に表示される警告

Unityでファイルを作成した場合に改行コードが「\n」になっているため、そのファイルをテキストエディタで編集した際にテキストエディタによってその他改行コードの挿入がされること等により発生します。

「\r」「\n」「\r\n」いずれかに統一すれば解消されます。

There are inconsistent line endings in the 'XXXX.cs' script. Some are Mac OS X (UNIX) and some are Windows.
This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands.

エラー

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Graphs.Edge.WakeUp () (at /Users/builduser/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/Edge.cs:114)
UnityEditor.Graphs.Graph.DoWakeUpEdges (System.Collections.Generic.List`1 inEdges, System.Collections.Generic.List`1 ok, System.Collections.Generic.List`1 error, Boolean inEdgesUsedToBeValid) (at /Users/builduser/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/Graph.cs:387)
UnityEditor.Graphs.Graph.WakeUpEdges (Boolean clearSlotEdges) (at /Users/builduser/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/Graph.cs:286)
UnityEditor.Graphs.Graph.WakeUp (Boolean force) (at /Users/builduser/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/Graph.cs:272)
UnityEditor.Graphs.Graph.WakeUp () (at /Users/builduser/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/Graph.cs:250)
UnityEditor.Graphs.Graph.OnEnable () (at /Users/builduser/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/Graph.cs:245)

Parent of RectTransform is being set with parent property.

エラー表示例

Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.
UnityEngine.Transform:set_parent(Transform)
SampleSceneController:Start() (at Assets/SampleSceneController.cs:24)

Rect Transformコンポーネントを持つオブジェクトの親をparentプロパティで設定した場合に発生します。

TestObj.transform.parent = ParentObj.transform;

parentプロパティの代わりにSetParent()関数を使用して設定することで解消します。

TestObj.transform.SetParent( ParentObj.transform );

関連リンク

https://docs.unity3d.com/ja/current/Manual/class-RectTransform.html

Scene couldn't be loaded

エラー表示例

Scene 'TestScene' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
To add a scene to the build settings use the menu File->Build Settings...
UnityEngine.SceneManagement.SceneManager:LoadScene(String)
Sample:Update() (at Assets/Sample.cs:XX)

Default audio device was changed, but the audio system failed to initialize it. Attempting to reset sound system.

イヤホン抜き差しした際発生

'UnityWebRequest.Send()' は旧形式です

エラー表示例

/Users/test/TestProject/Assets/Scripts/test.cs(XX,XX): Warning CS0618: 'UnityWebRequest.Send()' は旧形式です ('Use SendWebRequest.  It returns a UnityWebRequestAsyncOperation which contains a reference to the WebRequest object.') (CS0618) (Assembly-CSharp)

確認環境

Unity Version 2019.1.8f1 Personal

UnityWebRequest unityWebRequest = UnityWebRequestMultimedia.GetAudioClip("file://" + soundPath, AudioType.OGGVORBIS);
yield return unityWebRequest.Send();

UnityWebRequest.Send()にObsolete属性が追加され、UnityWebRequest.SendWebRequest()を使用する形に修正で解消されます。

UnityWebRequest unityWebRequest = UnityWebRequestMultimedia.GetAudioClip("file://" + soundPath, AudioType.OGGVORBIS);
yield return unityWebRequest.SendWebRequest();

https://docs.unity3d.com/ja/current/ScriptReference/Networking.UnityWebRequest.Send.html

https://docs.unity3d.com/ja/2017.4/ScriptReference/Networking.UnityWebRequest.SendWebRequest.html

濁音がつく文字を表示すると濁音が別の一文字として表示される。

確認環境

Unity Version 2019.1.8f1 Personal

プレビュー バージョン 8.1 (877.7)

表示内容

通常以下のように表示されるものが

がぎぐげご

以下のように表示されます。

か゛き゛く゛け゛こ゛

発生原因

Macのプレビューで表示したPDFからテキストをコピーした際等に発生します。

濁音付きの1文字として表示される形式に正規化されているかの確認方法

IsNormalized()メソッドで確認可能です。引数に判定するUnicode 正規形を指定できますが、引数を渡さない場合Unicode 正規形 Cとして判定されます。

戻り値が真の場合は正規化されています。

正規化されていない文字列はNormalize()メソッドで正規化が行えます。

string str = "がぎぐげご";
bool isNormalized = str.IsNormalized();
if(isNormalized)
{
  Debug.Log("Unicode 正規形 Cに正規化されています。濁音が付いている文字も1文字で表示されます。");
  Debug.Log("str : " + str);
}
else
{
  Debug.Log("Unicode 正規形 Cに正規化されていません。濁音が付いている文字は濁音が別の文字として表示されます。");
  Debug.Log("str : " + str);

  string str_normalized = str.Normalize();
  Debug.Log("str_normalized : " + str_normalized);
}

濁音が別の文字として表示される形式はUnicode 正規形 Dなので、IsNormalized()メソッドの引数にその値を指定すると真偽が逆になります。

string str = "がぎぐげご";
bool isNormalized = str.IsNormalized(NormalizationForm.FormD);
if(isNormalized)
{
  Debug.Log("Unicode 正規形 Cに正規化されていません。濁音が付いている文字は濁音が別の文字として表示されます。");
  Debug.Log("str : " + str);

  string str_normalized = str.Normalize();
  Debug.Log("str_normalized : " + str_normalized);
}
else
{
  Debug.Log("Unicode 正規形 Cに正規化されています。濁音が付いている文字も1文字で表示されます。");
  Debug.Log("str : " + str);
}

関連リンク

https://docs.microsoft.com/ja-jp/dotnet/api/system.string.isnormalized?view=netframework-4.8

https://docs.microsoft.com/ja-jp/dotnet/api/system.string.normalize?view=netframework-4.8

-

Ignoring depth surface load action as it is memoryless
Ignoring depth surface store action as it is memoryless