How to assign a rigidbody in custom inspector?

Hello there, i want to create a field in a custom inspector where i can assign a rigidbody but i get an error in this code:

        public override void OnInspectorGUI() {
            base.OnInspectorGUI();
            var myScript = target as Grabable;
            
            if(myScript.grabType == Grabable.GRAB_TYPE.FORCE) {
                myScript.connectedRigidBody = EditorGUILayout.ObjectField("Connected Rigidbody",  
                                              myScript.connectedRigidBody, typeof(Rigidbody), true);

            }
        }

Error: “Cannot convert type UnityEngine.Object to UnityEngine.Rigidbody - are you missing a cast?”

How can i actually assign a rigidbody there? Casting the Rigidbody into a UnityEngine.Object is redundant (says Unity),

Greets :slight_smile:

Other way around- ObjectField returns a UnityEngine.Object, you need to cast that returned object to a Rigidbody. Just add “as Rigidbody;” to the end of that line, or (Rigidbody) to the beginning, like:

myScript.connectedRigidBody = (Rigidbody)EditorGUILayout.ObjectField("Connected Rigidbody", myScript.connectedRigidBody, typeof(Rigidbody), true);