Grab MonoScript from Instance (non ScriptableObject)

Hey

I have a class that I want to display in the Unity editor. For the user to get the filename, and doubleclick to open the file. This is a lot like the “Script” section on all MonoBehaviours in the editor.

So I worked out, if I have the property:

public MonoScript monoScript;

I can then access my script from the project panel and it will assign. When I doubleclick it it opens the file. Which means there is a MonoScript for my class.

However, I have an object which is an instance of a class that I want to assign. Is there anyway of grabbing the MonoScript version of my instance?

I also don’t mind using the UnityEditor class. As it’s just a reference for the programmer.

Thanks,

James

I know this answer is a bit old but this is the second result when I searched for the same thing. You will need this method
MonoScript.FromMonoBehaviour