B
B
BRIOONI2021-01-26 17:28:38
Unity
BRIOONI, 2021-01-26 17:28:38

Writes NullReferenceException: Object reference not set to an instance of an object Platform. What to do>?

Script:

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

public class Platform : MonoBehaviour
{
    public float forceJump;                                       

    public void OnCollisionEnter2D(Collision2D collision)           
    {
        if (collision.relativeVelocity.y < 0)                       
        {
            Doodle.instance.DoodleRigid.velocity = Vector2.up * forceJump;    
        }        
    }
     
}

Error: NullReferenceException: Object reference not set to an instance of an object
Platform.OnCollisionEnter2D (UnityEngine.Collision2D collision) (at Assets/Scripts Game/Platform.cs:13)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CHIDWI, 2021-02-05
@CHIDWI

NullReferenceException this error in 99% of cases means that you are accessing an object that is empty (null). Basically, this means that it is not tightened where it should be. BUT! In this case, the compiler writes that on line 13 you are accessing an object that is null. Most likely there is no rigidbody2d on this object or there is no access to it. To find errors, I recommend reading the logs and using Debug.Log();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question