Hello! My root entity at script is record, so when I am trying to get class from MonoScript it is always null. Idk is it by intension, but without it I couldn identify those
It’s working for me.
In the Editor
folder: TestMonoScript.cs
using JustToShow;
using UnityEditor;
using UnityEngine;
public class TestMonoScript : MonoBehaviour
{
[MenuItem("Test/MonoScript")]
private static void TestMS()
{
Debug.Log(MonoScript.FromMonoBehaviour(FindObjectOfType<Test>()).GetClass());
}
}
Not in an Editor
folder Test.cs
:
using UnityEngine;
namespace JustToShow
{
public class Test : MonoBehaviour {}
}
I have a game object in the scene which has the Test
component on it.
I have the Test/MonoScript
menu in the editor, hitting the menu-point:
Are you sure you do not have errors in the console? And/or using ASMDEF?
MonoScript only works for MonoBehaviours and ScriptableObjects, all other classes aren’t considered MonoScripts
I think it needs better explanation. I am alredy working with MonoScript in my project. But now, in Unity 21.2 I am trying to use records instead of classes, and can’t get any link from MonoScript object to my record which placed inside MonoScript. Records it a new feature of C# so maybe it need to be handled somehow inside MonoScriprt. I have added screenshot!
https://docs.unity3d.com/2021.2/Documentation/Manual/CSharpCompiler.html
Records are officially unsupported feature.
Edit: although I have to add, on Windows, purely using records seems to be working and building without error message. But since Unity stated that they don’t support them, it is very risky to use them.
I see now, thanks! Tho that’s sad