fix: resolve Roslyn assemblies on macOS (Unity.app/Contents path)#13
Open
dougfy wants to merge 1 commit intoAnkleBreaker-Studio:mainfrom
Open
fix: resolve Roslyn assemblies on macOS (Unity.app/Contents path)#13dougfy wants to merge 1 commit intoAnkleBreaker-Studio:mainfrom
dougfy wants to merge 1 commit intoAnkleBreaker-Studio:mainfrom
Conversation
On macOS, EditorApplication.applicationPath points to the Unity.app bundle itself (e.g. /Applications/Unity/Hub/Editor/2022.3.62f2/Unity.app). The previous code called Path.GetDirectoryName() on that path and then appended 'Data/...' — a layout that only exists on Windows and Linux. On macOS the Roslyn DLLs live inside Unity.app/Contents/..., so TryLoadRoslyn() never found them and ExecuteCode always returned the 'Roslyn is not available' error. Fix: detect when applicationPath ends in '.app' and add Unity.app/Contents as an additional data root alongside the existing Windows/Linux root. Also adds Tools/ScriptUpdater as a search location (ships Mono-compatible Roslyn assemblies in all 2022.3.x builds). Tested on macOS (Unity 2022.3.62f2, Apple Silicon).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On macOS,
EditorApplication.applicationPathreturns the path to theUnity.appbundle itself (e.g./Applications/Unity/Hub/Editor/2022.3.62f2/Unity.app).The existing
TryLoadRoslyn()callsPath.GetDirectoryName()on that path and then appendsData/...— a layout that only exists on Windows and Linux. On macOS the Roslyn DLLs live insideUnity.app/Contents/..., so all search paths miss andExecuteCodealways returns:This affects all Unity 2022.3.x and Unity 6 installs on macOS, even though the required DLLs (
Microsoft.CodeAnalysis.dll,Microsoft.CodeAnalysis.CSharp.dll) are bundled in every Unity release.Fix
Detect when
applicationPathends in.appand addUnity.app/Contentsas an additional data root alongside the existing Windows/LinuxDataroot. The search loop already handles missing directories gracefully, so this is a safe additive change.Also adds
Tools/ScriptUpdateras a search location — it ships Mono-compatible Roslyn assemblies in all 2022.3.x builds and is a reliable fallback.Tested
unity_execute_codenow returns results instead of the Roslyn error