Start the edition of a script programatically

Hi! I’m developing an extension of Unity, but I’m having a problem.

I need to open any script (inside the editor) programatically, and that script should be openned in the mono/msvs project, exactly like when you double click a script.

I’ve tried using “EditorUtility.OpenWithDefaultApp(fileName);” but it opens the individual file, not inside the project.

Anyone could solve this?

Regards!

AssetDatabase.OpenAsset() works for me, though I have to use MonoScript.FromMonoBehavior() or MonoScript.FromScriptableObject() to get an appropriate object to pass to OpenAsset(). Which means that I have to actually have an instance of the script available. I’ve tried to figure out how to go from script filename to a MonoScript instance, but I don’t recall having succeeded.

Hmm, a little bit of research suggests that AssetDatabase.LoadMainAssetFromPath() would also return a valid object to pass to OpenAsset(). So maybe try the following:

AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetFromPath(fileName));
1 Like

Thank youuuu! I didn’t know how to look for it! Thanksss :smile: