コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】キレイにループ再生したい時は .mp3 ではなく .ogg を使用する

参考サイト様 結論から言うと、どうもMP3は連続再生でのループに向いていない形式のようです。 WAVファイルからMP3ファイルに変換する際、 元データには無い余計な無音部分が先頭、 または末尾に勝手に挿入されてしまうからです。

【Unity】iOS ビルドなのにAndroid Resolver が走ってしまう場合

概要 MenuItem から iOS ビルドする時に Android Resolver が走ってしまう現象に遭遇した PlayerSettings.Android.targetArchitectures = AndroidArchitecture.ARM64; iOS ビルド時にも PlayerSettings.Android のプロパティを操作していることが原因だった …

【Unity】Burst requires the android NDK to be correctly installed

概要 BuildFailedException: Burst compiler (1.7.3) failed running stdout: Burst requires the android NDK to be correctly installed (it can be installed via the unity installer add component) in order to build a standalone player for Android…

【Unity】Failed to register for remote notifications

概要 Firebase Cloud Messaging を導入した Unity プロジェクトを iOS ビルドして動作確認したところ Failed to register for remote notifications 上記のエラーが発生する現象に遭遇した Mobile Notifications パッケージの Project Settings で 「Enable …

【Unity】Firebase.FirebaseException: We have blocked all requests from this device due to unusual activity. Try again later.

概要 Firebase.FirebaseException: We have blocked all requests from this device due to unusual activity. Try again later. FirebaseUser.SendEmailVerificationAsync を何回か試していたら 途中から上記の例外が発生して動作確認ができなくなってしま…

【Unity】Firebase.FirebaseException: The email address is badly formatted.

概要 Firebase.FirebaseException: The email address is badly formatted. FirebaseAuth.SignInWithEmailAndPasswordAsync を使用した時に 上記の例外が発生する現象に遭遇した パスワードの文字列をよく見てみたらアットマーク @ が 半角ではなく全角にな…

【Unity】GvhProjectSettings.xml が勝手に変更される

概要 Firebase を導入した Unity プロジェクトで GvhProjectSettings.xml が勝手に変更される 現象に遭遇した 公式の GitHub で Issue が作られていたが、まだ解決していないようだった 検証環境 Unity 2022.1.11f1 macOS Monterey バージョン 12.5.1 MacBoo…

【Unity】3D Object の TextMesh Pro の色が正しく反映されない場合の対処方法

はじめに Vertex Color に設定した色より薄く表示される 3D Object の TextMesh Pro は Vertex Color に設定した色が 正しく反映されないことがあるのでその対処方法 目次 はじめに 目次 検証環境 対処方法1:TextMesh Pro を 3.2.0-pre.3 にアップデートす…

【Unity】ArgumentException: Can't save a Prefab instance

概要 PrefabUtility.SavePrefabAsset( prefab ); PrefabUtility.SavePrefabAsset でプレハブを保存しようとして ArgumentException: Can't save a Prefab instance 上記のエラーが発生する場合は PrefabUtility.SaveAsPrefabAsset( prefab, prefabPath ); Pr…

【Unity】Calling OnPostBuildPlayerScriptDLLs callbacks. For faster build speeds, consider not using this callback, as we don't need to copy assemblies to the staging area for the incremental player build otherwise.

概要 Calling OnPostBuildPlayerScriptDLLs callbacks. For faster build speeds, consider not using this callback, as we don't need to copy assemblies to the staging area for the incremental player build otherwise. ビルド時に上記のログが出力さ…

【Unity】JNI:GetAudioStreamVolume:java.lang.SecurityException: listen

概要 JNI:GetAudioStreamVolume:java.lang.SecurityException: listen Unity 2022.1.11f1 で Android ビルドしたところ アプリ起動直後に上記のエラーログが出力されていた 最新の Unity バージョンなら直っているようだったので Unity 2022.1.20f1 で Andro…

【Unity】The operation couldn't be completed. Unable to locate a Java Runtime.

概要 Gradle failed to fetch dependencies. Failed to run 'XXXX/UnityProject/Temp/PlayServicesResolverGradle/gradlew --no-daemon -b "XXXX/UnityProject/Temp/PlayServicesResolverGradle/PlayServicesResolver.scripts.download_artifacts.gradle" "-…

【Unity】FirebaseCppApp-9_6_0.bundle が 100 MB を超えており GitHub リポジトリに Push できない場合

概要 remote: error: See http://git.io/iEPt8g for more information. remote: error: File UnityProject/Assets/Firebase/Plugins/x86_64/FirebaseCppApp-9_6_0.bundle is 134.36 MB; this exceeds GitHub's file size limit of 100.00 MB remote: error: …

【Unity】Firebase を使っているプロジェクトの iOS ビルドで .xcworkspace ではなく .xcodeproj を生成する方法

概要 Unity メニューの「Assets > External Dependency Manager > iOS Resolver > Settings」の 「Cocoapods Integration」を「Xcode Project~」にすると iOS ビルドで .xcworkspace ではなく .xcodeproj が生成されるようになる

【Unity】Execution failed for task ':launcher:processReleaseResources'.

概要 CommandInvokationFailure: Gradle build failed. C:\Program Files\Unity\Hub\Editor\2022.1.11f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2022.1.11f1\Editor\Data\Playback…

【Unity】iOS framework addition failed due to a CocoaPods installation failure. This will will likely result in an non-functional Xcode project.

概要 iOS framework addition failed due to a CocoaPods installation failure. This will will likely result in an non-functional Xcode project. After the failure, "pod repo update" was executed and failed. "pod install" was then attempted aga…

【Unity】Android 13 で通知許可ダイアログを開く時に無限ループが発生してしまう場合

概要 Mobile Notifications 2.1.0 を使用して Android 13 で通知許可ダイアログを開く時に 無限ループが発生してしまう場合、 「Project Settings > Player > Target API Level」を「API level 33」にしてから ビルドし直すと通知許可ダイアログが正常に開け…

【Unity】Notifications are not allowed for this application

はじめに Mobile Notifications を使用して iOS で通知許可ダイアログを表示しようとしたところ Notifications are not allowed for this application Requesting notification authorization failed with: Error Domain=UNErrorDomain Code=1 "Notification…

【Unity】Non-secure network connections disabled in Player Settings

概要 Non-secure network connections disabled in Player Settings System.Reflection.MethodBase:Invoke (object,object[]) Google.PortableWebRequest:StartRequest (Google.PortableWebRequest/HttpMethod,string,System.Collections.Generic.IDictionar…

【Unity】error: Build input file cannot be found: 'XXXX/YYYY.mm' (in target 'UnityFramework' from project 'Unity-iPhone')

概要 error: Build input file cannot be found: 'XXXX/YYYY.mm' (in target 'UnityFramework' from project 'Unity-iPhone') .mm ファイルの管理フォルダを変更したあとに Unity で iOS ビルドしたら Xcode ビルド時に上記のエラーが発生する現象に遭遇した…

【Unity】Assertion failed on expression: 'it != m_SendMap.end()'

概要 AcceleratorClientConnectionCallback - disconnected - 192.168.0.6:10080 Assertion failed on expression: 'it != m_SendMap.end()' ================================================================= Native Crash Reporting ==================…

【Unity】プレハブモードで FindObjectOfType を使いたい場合

概要 var tilemap = GameObject.FindObjectOfType<Tilemap>(); プレハブモードでは FindObjectOfType を使ってもコンポーネントは見つからない var tilemap = PrefabStageUtility .GetCurrentPrefabStage() .FindComponentOfType<Tilemap>() ; 上記のようなコードを書くとコン</tilemap></tilemap>…

【Unity】AssetPostprocessor の OnPreprocessAudio や OnPreprocessTexture だと ScriptableSingleton の最新の情報を取得できなかった

概要 private void OnPreprocessAudio() { var example = Example.instance; } AssetPostprocessor の OnPreprocessAudio や OnPreprocessTexture で ScriptableSingleton にアクセスしたところ、初回は正常に値を取得できたが ScriptableSingleton の値を変…

【Unity】Sprite Atlas V2 だと SetPackingSettings や SetTextureSettings が反映されない

概要 [MenuItem( "hoge/hoge" )] private static void Hoge() { var assetPath = "Assets/New Sprite Atlas.spriteatlas"; var spriteAtlas = AssetDatabase.LoadAssetAtPath<SpriteAtlas>( assetPath ); var packingSettings = spriteAtlas.GetPackingSettings(); packin</spriteatlas>…

【Unity】SpriteAtlas V2 を有効にした場合の SpriteAtlas の拡張子は .spriteatlasv2

概要 var list = importedAssets .Where( x => x.EndsWith( ".spriteatlas" ) || x.EndsWith( ".spriteatlasv2" ) ) .ToArray() ; アセットのパスの拡張子で SpriteAtlas かどうかを確認する場合は .spriteatlas だけではなく .spriteatlasv2 も確認する必要…

【Unity】AssetPostprocessor の OnPreprocessAudio や OnPreprocessTexture では Application.isBatchMode が true になる

概要 Unity Hub から Unity を起動した状態で [MenuItem( "hoge/hoge" )] private static void Hoge() { Debug.Log( Application.isBatchMode ); // False } Application.isBatchMode にアクセスすると通常は False になるが private void OnPreprocessAudio…

【Unity】エディタの GUI を上下の中央に表示する方法

概要 using var scope = new EditorGUILayout.VerticalScope(); GUILayout.FlexibleSpace(); if ( GUILayout.Button( icon, EditorStyles.iconButton ) ) { } GUILayout.FlexibleSpace(); EditorGUILayout.VerticalScope と GUILayout.FlexibleSpace を組み…

【Unity】エディタの GUI でリストに要素がドラッグされたかどうかを検知する方法

概要 using var scope = new EditorGUI.ChangeCheckScope(); var oldCount = m_list.Count; m_editor.OnInspectorGUI(); if ( !scope.changed && oldCount == m_list.Count ) return; Debug.Log( "ピカチュウ" ); エディタの GUI でリストに要素がドラッグさ…

【Unity】Duplicate Array Element と Delete Array Element を実行した時は ChangeCheckScope.changed は true にならない

【Unity】Hierarchy の Create メニューから EventSystem が作成できなくなった時の対処方法

概要 EventSystem の Preset を作成して Preset Manager に登録したら Hierarchy の Create メニューから EventSystem が作成できなくなった Unity を再起動したら作成できるように直った 開発環境 Unity 2022.1.11f1 macOS Monterey バージョン 12.5.1