Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Discussion Official I got null reference exception when i switch between scenes I use try and catch to caught

Discussion in 'Scripting' started by sachinhello, Dec 21, 2022.

  1. sachinhello

    sachinhello

    Joined:
    Dec 27, 2018
    Posts:
    16
    I am using unity web request and make a helper class and using static method to hit on web to get data
    I am using async and await for waiting to get data and response from server in between i switch scene then i got error i am sharing my method signature to understand better which cause the problem what is the efficent way to prevent null reference logs.

    public static async Task<short> GetRequest(string url, Action<string> jsonresponseAction = null, Action<string> responseFailedAction = null, string token = null, int timeout = 0)

    error cause when using callback to get jsonresponseAction data
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,222
    PraetorBlue and tsukimi like this.
  3. sachinhello

    sachinhello

    Joined:
    Dec 27, 2018
    Posts:
    16
    i am using this condition to avoid null reference exception in my request callback
    if(!this)
    return;
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,222
    That sounds like you misidentified what is null.