Search Unity

[Solved]Delegate function lost parameter value on ios + assetbundles

Discussion in 'Scripting' started by TobyKaos, Apr 27, 2020.

  1. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    Hello, I have a strange issue with Delegate function.

    I have a callback using a System.Action<Menu> delegate. since 1 year all is ok but now an issue appear when I use delegate with assetBundles on ios. The value of parameter passed in delegate is null (visual studio tell me he cannot evaluate it).

    My callback is called like this

    Code (CSharp):
    1.  
    2. public void MyFunction(string paramIn, Action<Menu> callback)
    3. {
    4. //My menu instance
    5. Menu myMenu = MenuManager.Instance.GetMenu(); // here all is ok, menu exists
    6. if(callback != null)
    7.   callback(menu);
    8. }
    In my delegate I have try with lambda expression and type expression like this
    Code (CSharp):
    1.  
    2. MyFunction(paramIn, delegate(Menu menu)
    3. {
    4.     menu.text = "Hello"; // here menu is null and visual studio tell me: identifier is not in the scope
    5.  
    6. });

    What is strange is that on Android it is working. On ios without AssetBundles all is ok. I I build AssetBundles for IOS and load scenes from assetBundles the value of menu is null.
    And very strange if in the delegate I call MenuManager.Instance.GetMenu() I got the value of menu.

    I think all delegate lost parameter ref in the case I load assetbundles. I think this appears after a build that failed due to disk storage space.

    Then I have clean my disk storage, reinstall unity and delete Libray folder. Rebuild all AssetBundles.

    I do not know what to do more

    I use Unity 2019.3.9f1 and upgrade to 2019.3.11f1.
     
    Last edited: Apr 27, 2020
  2. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    Some others tests:

    I try this:

    Code (CSharp):
    1.  
    2. Menu testMenu = GetMenu(); // ok got an instance of Popup_General in base class Menu
    3.  
    4. Popup_General popup = testMenu as Popup_General; // the conversion seems to be done but popup is out of the scope
    5.  
    6. popup.text = "hello"; // crash
    7.  
     
    Last edited: Apr 27, 2020
  3. olejuer

    olejuer

    Joined:
    Dec 1, 2014
    Posts:
    211
  4. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    I found my error. Visual studio had make me think that is it a lost of reference because it tell me that the value is not in the scope. But the error was elsewhere.