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

NullReferenceException: : SerializedProperty is null

Discussion in 'Scripting' started by vendettav, Sep 11, 2021.

  1. vendettav

    vendettav

    Joined:
    Mar 16, 2019
    Posts:
    9
    I just import Beginner Code Kit
    upload_2021-9-11_23-55-39.png

    And add new Enum type in upload_2021-9-11_23-56-20.png

    But it cant work perfectly when my Editor thow error all the time. Help me

    upload_2021-9-11_23-56-58.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,947
    It's no different than any other nullref. If your code change brought that on, to fix it you have to find out what the null reference is.

    If I had to completely wildly speculate, by adding that extra enum entry, perhaps there's another entry of something that must be added as well, and you haven't done that.

    But again, same steps apply as any other Nullref:

    - Identify what is null
    - Identify why it is null
    - Fix that.
     
  3. vendettav

    vendettav

    Joined:
    Mar 16, 2019
    Posts:
    9
    I know and I had checkout all things but seem nothing wrong. The array is locked with 4 element lenth by somehow. U can import the project and try. It dont take the long time.
    upload_2021-9-12_8-39-35.png

    upload_2021-9-12_8-27-46.png



    upload_2021-9-12_8-28-10.png
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,947
    What happens if you right-click the script's hamburger and hit Reset?
     
    vendettav likes this.
  5. vendettav

    vendettav

    Joined:
    Mar 16, 2019
    Posts:
    9
    Wow, genius. Thanks u so much
     
    Kurt-Dekker likes this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,947
    Squinting further at it, if I had to guess what actually happened:

    I bet it is because the two class instance level constructors for the Stats arrays are getting overwritten by stored serialized data, bringing them back to size 4, even though you made 'em now 5.

    So I'm saying, they are created at
    new
    time as size 5, then overwritten with size 4 data at the deserialize, then your code runs and boom.

    Your hitting Reset nukes the too-small serialized data.
     
    vendettav likes this.