Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GetProperty returns null in build

Discussion in 'Scripting' started by Darkkingdom, Oct 29, 2019.

  1. Darkkingdom

    Darkkingdom

    Joined:
    Sep 2, 2014
    Posts:
    81
    Hey guys,

    I tried to load the attached snapshots of my AudioMixer with this line:
    Code (CSharp):
    1. AudioMixerSnapshot[] mySnapshots = (AudioMixerSnapshot[])myMixer.GetType().GetProperty("snapshots").GetValue(myMixer, null);
    I works really well in Editor but when I build the game the GetProperty() always returns null.
    With myMixer.GetType().GetProperties(); I was able to see all propertys the mixer has. In the editor it's:

    • allGroups
    • numExposedParameters
    • exposedParameters
    • masterGroup
    • startSnapshot
    • TargetSnapshot
    • snapshots
    • CachedSelection
    • currentViewIndex
    • views
    • isSuspended
    • outputAudioMixerGroup
    • updateMode
    • name
    • hideFlags
    But in build only those exist:

    • updateMode
    • name
    • hideFlags
    Does anyone have an idea?

    Somehow this seems like an bug to me


    Thank you!
     
  2. Darkkingdom

    Darkkingdom

    Joined:
    Sep 2, 2014
    Posts:
    81
    Has someone an idea?
    Maybe just a idea how to debug the problem further? I'm pretty lost here^^
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    If there are properties that you can access only through reflection ("GetProperty", etc), that's a good indicator that those properties are not meant to be used casually. A few good rules to follow if you're using Reflection are 1) Expect undocumented behavior, 2) Don't expect the property to be there or to work identically in future Unity versions, and 3) Don't expect the property to function as advertised in a build.

    Considering this to be a bug would be basically breaking into someone's house and then complaining that their sink doesn't work. Can you get some functionality out of undocumented functions? Sure, sometimes, but they're undocumented for a reason.

    You'll have to figure out how to get the desired functionality with the methods that are available to you in a build (which generally means, using the documented functions). I unfortunately am not super familiar with AudioMixer so I can't guide you on that.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    How are you making this determination? That is, how are you debugging? https://forum.unity.com/threads/tips-for-new-unity-users.701864/#post-5057741