0

This is my code:

using UnityEngine;

public class movement : MonoBehaviour
{
    public Rigidbody rb;
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        rb.AddForce(0,0,2000 * Time.deltaTime);
    
    }
}

This the error:

ArgumentNullException: Value cannot be null.
Parameter name: _unity_self
UnityEditor.SerializedObject.FindProperty (System.String propertyPath) (at <582c35e8f45345d395e99f8e72e3c16d>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindPropertyRelative (UnityEngine.UIElements.IBindable field, UnityEditor.SerializedProperty parentProperty) (at <af95451922f042e9a8d1a10956fb36a2>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <af95451922f042e9a8d1a10956fb36a2>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.ContinueBinding (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <af95451922f042e9a8d1a10956fb36a2>:0)
UnityEditor.UIElements.Bindings.DefaultSerializedObjectBindingImplementation+BindingRequest.Bind (UnityEngine.UIElements.VisualElement element) (at <af95451922f042e9a8d1a10956fb36a2>:0)
UnityEngine.UIElements.VisualTreeBindingsUpdater.Update () (at <d293f45b4ec64e6c9e762fe89794e7a5>:0)
UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <d293f45b4ec64e6c9e762fe89794e7a5>:0)
UnityEngine.UIElements.Panel.UpdateBindings () (at <d293f45b4ec64e6c9e762fe89794e7a5>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <d293f45b4ec64e6c9e762fe89794e7a5>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <d293f45b4ec64e6c9e762fe89794e7a5>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <af95451922f042e9a8d1a10956fb36a2>:0)
wohlstad
  • 12,661
  • 10
  • 26
  • 39
  • 4
    `rb` doesn't seem to get initialized, is it? – Fildor Jun 12 '23 at 12:46
  • 1
    Since this is unity code, it is possible that the RigidBody `rb` is dragged and dropped in the editor. Did you do that? – Marnix Jun 12 '23 at 12:50
  • 1
    i assume you're a beginner. to rephrase @Fildor's question, in the movement script, when you have a public variable like rb, you have to assign an object to that. did you do that? – Molbac Jun 12 '23 at 12:50

1 Answers1

3

rb is not assigned in your code, or in the Unity inspector.

public class movement : MonoBehaviour
{
    public Rigidbody rb;
    // Start is called before the first frame update
    void Start()
    {
       rb = gameObject.GetComponent<Rigidbody>();
    }

    //your code....
}
tim the fiend
  • 179
  • 1
  • 1
  • 9