Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question "Thing" not set to a an instance of an object

Discussion in 'Editor & General Support' started by kenethbuenhumor, May 26, 2024.

  1. kenethbuenhumor

    kenethbuenhumor

    Joined:
    May 26, 2024
    Posts:
    5
    i was working on this tutorial doing the camera ledge detection and I already checked for misspelling or misplacement but I found none. I am getting this error which no matter what I do I cannot fix. The error is below and the code is below it. Pleasee help.



    NullReferenceException: Object reference not set to an instance of an object
    CameraControlTrigger.OnTriggerEnter2D (UnityEngine.Collider2D collision) (at Assets/Scripts/Game/Cameras/CameraControlTrigger.cs:25)

    NullReferenceException: Object reference not set to an instance of an object
    CameraControlTrigger.OnTriggerExit2D (UnityEngine.Collider2D collision) (at Assets/Scripts/Game/Cameras/CameraControlTrigger.cs:37)

    private void OnTriggerEnter2D(Collider2D collision)
    {
    if (collision.CompareTag("Player"))
    {
    if (customInspectorObjects.panCameraOnContact)
    {
    //pan the camera
    CameraManager.instance.PanCameraOnContact(customInspectorObjects.panDistance, customInspectorObjects.panTime, customInspectorObjects.panDirection, false); //this is line 25
    }
    }
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
    if (collision.CompareTag("Player"))
    {
    if (customInspectorObjects.panCameraOnContact)
    {
    //pan the camera
    CameraManager.instance.PanCameraOnContact(customInspectorObjects.panDistance, customInspectorObjects.panTime, customInspectorObjects.panDirection, true); //this is line 37
    }
    }
    }
    }

    This is the PanCamercaOnContact from the Camera Manager script

    public void PanCameraOnContact(float panDistance, float panTime, PanDirection panDirection, bool panToStartingPos)
    {
    _panCameraCoroutine = StartCoroutine(PanCamera(panDistance, panTime, panDirection, panToStartingPos));
    }

    This is what happens in-game
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,371
    bugfinders likes this.
  3. kenethbuenhumor

    kenethbuenhumor

    Joined:
    May 26, 2024
    Posts:
    5
    I just created my account today I do not know any of the rules, apologies. Idon't understand something tho. I already showed in this thread what is null, did I do it wrong or are you just sending me a copy paste of a message?
     
  4. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,170
    click on the blue links at bottom of console, see if you have any error in the code
     
  5. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,169
    No but the error also will tell you exactly which line the error occurs in, and from there you can work out what is null
     
  6. kenethbuenhumor

    kenethbuenhumor

    Joined:
    May 26, 2024
    Posts:
    5
    Thank you, I managed to fix it. I simply said if null then this equals this