Need some help with this error.

Hello,

How can I solve this error? I already searched it in google and in other webstites,but I still don´t know how to fix it.

NullReferenceException: Object reference not set to an instance of an object
ParedRompible.Romper () (at Assets/Scripts/Player/ParedRompible.cs:35)

This is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ParedRompible : MonoBehaviour
{
    [SerializeField] private float vida;

    private Explodable _explodable;


    private void Start()
    {

        _explodable = GetComponent<Explodable>();
    }



    public void TomarDaño(float daño)
    {
        vida -= daño;

        if (vida <= 0)
        {
            Romper();
        }

    }

    private void Romper()
    {
        _explodable.explode();
        ExplosionForce ef = GameObject.FindObjectOfType<ExplosionForce>();
        ef.doExplosion(transform.position);


        Debug.Log("hola");
    }




}

Thanks for your time;

Ok so that line at the end is not in the code I put it there by accident (47).

It is irrelevant what you are doing. The answer is always the same:

How to fix a NullReferenceException error

https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

Steps to success:

  • Identify what is null
  • Identify why it is null
  • Fix that

I’ll give you a clue, it says it’s on line 35, in the thread kurt referred to above, it talks about an empty jar, are you trying to get something from an empty jar?