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. Dismiss Notice

Question NullReference when trying to retreive boxed value from SerializedProperty

Discussion in 'Scripting' started by Midonk, Mar 15, 2023.

  1. Midonk

    Midonk

    Joined:
    Oct 8, 2018
    Posts:
    34
    Hello ! I have an AudioMixerGroup as a SerializedObject.
    try to fetch the GUID of its "m_Volume" property.
    The "type" is indeed a GUID, the "propertyType" is Generic
    I verified that the SerializedProperty is not null
    I tried to use boxedValue to get the GUID struct but I only get a null reference error
    Is there something I didn't understand ?

    Error stack
    upload_2023-3-15_18-13-30.png

    code implementation
    upload_2023-3-15_18-14-16.png
    AudioMixerGroup serialization
    upload_2023-3-15_18-14-41.png
     
    Last edited: Mar 16, 2023
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,143
    Start debugging. Is child null? Is the Property you are looking for null? You need to figure out what is null first!

    1. Find out what is null
    2. Find out why it's null
    3. Fix it

    The steps are pretty much the same always!
     
  3. Midonk

    Midonk

    Joined:
    Oct 8, 2018
    Posts:
    34
    None is null, neither the child (AudioMixerGroup as SerializedObject) nor the property (m_Volume)
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,143
    You verified this by debug.log those values?
    AudioUtils.cs line 121 has the null value. So, something is null there or you wouldn't get a null error.
     
  5. Midonk

    Midonk

    Joined:
    Oct 8, 2018
    Posts:
    34
    Yes, I verified it

    Test
    upload_2023-3-16_8-32-1.png
    Console
    upload_2023-3-16_8-32-19.png
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,143
  7. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    AFAIK unity really dislikes GUIDs, and doesn't serialize them.
     
  8. Midonk

    Midonk

    Joined:
    Oct 8, 2018
    Posts:
    34
    Ok, let's assume that Unity won't allow me to get the boxed value of this GUID...the question is, how do I access this property value then ? It is right there :(
     
  9. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,844
    Can you just get it as a string?
     
  10. Midonk

    Midonk

    Joined:
    Oct 8, 2018
    Posts:
    34
    It throws me a "Type is not a supported string value"