Hello.
I want to open a script file at a destination line and found out about UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(path, line)
But I can’t really get it to work. I tried providing either the full path like for example:
c:/MyProject/Assets/script.js
or the relative path like
/script.js
In MonoDevelop the script opens always at first line, while in Sublime for example it doesnt even open, instead it opens up a new empty file named ‘$(file)’ in the project folder itself (in my example c:/MyProject).
My use case was that I had a custom object field for behaviours where if you right click it will take you to the script of that behaviour. There could be a better way, but this seems to work:
var monoscript = MonoScript.FromMonoBehaviour(behaviour);
var scriptPath = AssetDatabase.GetAssetPath(monoscript);
UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(scriptPath, 0);
Upon debugging and inspecting the return value stored in scriptPath, I saw that the path starts from “Assets”. e.g. “Assets/Scripts/Test.cs” for example. (which is consistent with what the docs mention in GetAssetPath Unity - Scripting API: AssetDatabase.GetAssetPath). So it’s not absolute path, nor relative from project root like you’ve tried.