ArgumentNullException: Value cannot be null. parameter name: Source

Hi :slight_smile:
i am making a 2D game were the player can jump on enemies and kind of bounce of them if that makes sense. Whenever i try to jump of a enemy i don’t get the “bounce” and i get a error

ArgumentNullException: Value cannot be null. parameter name: Source

Enemy.JumpedOn () (at Assets/Scripts/Enemy.cs:23)
PlayerController.OnCollisionEnter2D (UnityEngine.Collision2D other) (at Assets/Scripts/PlayerController.cs:100)

This s from playercontroller.cs:100

    private void OnCollisionEnter2D(Collision2D other)
    { // Fiende och kollison med fiende 
        if (other.gameObject.tag == "Enemy")
        {
            Enemy enemy = other.gameObject.GetComponent<Enemy>();
            if (state == State.falling)
            {
                enemy.JumpedOn();
                Jump();
            
            }

 protected virtual void Start()
    {
        anim = GetComponent<Animator>();
        rb = GetComponent<Rigidbody2D>();
        death = GetComponent<AudioSource>();
    }

This is from Enemy.cs 23

    public void JumpedOn()
    {
        anim.SetTrigger("Death");
        death.Play();

        rb.velocity = Vector2.zero;
        rb.bodyType = RigidbodyType2D.Kinematic;
        GetComponent<Collider2D>().enabled = false;
    }

I know I’m a bit late but that might help someone else,
So (gameObject) where the G is a small letter means this gameobject(Player) that mean you are trying to access a function in a script that is not even exist, so try delete the gameObject it’s not necessary so the code will be like this:

private void OnCollisionEnter2D(Collision2D other)
     { // Fiende och kollison med fiende 
         if (other.CompareTag("Enemy"))
         {
             Enemy enemy = other.GetComponent<Enemy>();
             if (state == State.falling)
             {
                 enemy.JumpedOn();
                 Jump();
             
             }
  protected virtual void Start()
     {
         anim = GetComponent<Animator>();
         rb = GetComponent<Rigidbody2D>();
         death = GetComponent<AudioSource>();
     }

hope i helped someone