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.

Question IL2CPP regression - fails to resolve generic code that used to compile

Discussion in 'Experimental Scripting Previews' started by Baste, May 12, 2022.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,844
    I have some generic code in our project that's started spitting out IL2CPP errors on build. This is a regression, as the code used to work in older versions.

    Bug report is #1427322

    Specifically, the last version the bug is not present in is:
    2020.3.32f1

    The bug is present in:
    2020.3.33f1
    2021.3.0.f1

    The bug is not present in 2022.0.1f1, probably due to the changes to IL2CPP there.

    The repro project contains four files, which is as far as I managed to strip the project down:

    Code (csharp):
    1.  // IHasObject.cs
    2. public interface IHasObject {
    3.     object obj { get; }
    4. }
    5.  
    6. // ShapeTrigger.cs
    7. using UnityEngine;
    8.  
    9. public class ShapeTrigger<THasObject, TTrigger> : ScriptableObject
    10.     where TTrigger : ShapeTrigger<THasObject, TTrigger>
    11.     where THasObject    : IHasObject {
    12.  
    13.     public ShapeTriggerParent<THasObject, TTrigger> parent;
    14. }
    15.  
    16. //ShapeTriggerParent.cs
    17. using UnityEngine;
    18.  
    19. public class ShapeTriggerParent <THasObject, TTrigger> : ScriptableObject
    20.     where TTrigger   : ShapeTrigger<THasObject, TTrigger>
    21.     where THasObject : IHasObject {
    22.  
    23.     public THasObject data;
    24. }
    25.  
    26. //RainArea.cs
    27. public class RainArea : ShapeTriggerParent<RainArea.RainTriggerData, RainArea.RainTrigger> {
    28.  
    29.     public class RainTrigger : ShapeTrigger<RainTriggerData, RainTrigger> { }
    30.  
    31.     public class RainTriggerData : IHasObject {
    32.         public object obj => null;
    33.     }
    34. }
    35.  
    36.  
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,038
    Thanks for the bug report! We will investigate it.

    Can you share the error message here? There is some chance that we can recognize the issue and help with a work around earlier.
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,844
    Sure!

    Code (csharp):
    1. Field 'THasObject ShapeTriggerParent`2::data' from 'PATH_TO_PROJECT\Poroject_ShapeTriggerParent2020\Library\ScriptAssemblies\Assembly-CSharp.dll', exception Failed to resolve THasObject
    2. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    and

    Code (csharp):
    1. Field 'THasObject ShapeTriggerParent`2::data' from 'PATH_TO_PROJECT\Poroject_ShapeTriggerParent2020\Library\PlayerScriptAssemblies\Assembly-CSharp.dll', exception Failed to resolve THasObject
    2. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    The build still finishes when building to Windows Intel 64-bit. I haven't actually looked into what happens if we try to use any of the code, but I assume trying to grab data from a field that doesn't resolve would cause bad things.
    On at least one console, the build doesn't complete, though we get the same error (and some others, but we're investigating this first).
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,038
    Interesting - this is not something I recall seeing before. So unfortunately I cannot help with a work around now. We will investigate it though.
     
  5. BoppyGamesLLC

    BoppyGamesLLC

    Joined:
    May 1, 2020
    Posts:
    4
    I just upgraded my Unity version today and I'm having a similar compilation issue. When compiling with IL2cpp I get this error:


    Field 'T TerrainGeneration.TerrainDetail`1::generationOptions' from '...\Library\ScriptAssemblies\Assembly-CSharp.dll', exception Failed to resolve GenerationOptionType


    The type its complaining about is defined like this:


    public abstract class TerrainGenerationEngine<GenerationOptionType> : TerrainGenerationEngine
    where GenerationOptionType : IGeneratorOptions
    {
    ...
    }


    IGeneratorOptions is an interface.

    TerrainGenerationEngine (with no generic parameter) is abstract and extends MonoBehaviour.

    Going to try to downgrade for now. If you need more info let me know
     
  6. RickSaada1

    RickSaada1

    Joined:
    Mar 9, 2015
    Posts:
    9
    I'm seeing the same thing with the UIWidgets package (version 1.14.2) from the store. We just upgraded to 2021.3.0.2f1 and now we get :
    Field 'TPoint UIWidgets.TracksViewBase`2::valueAtCenter' from 'D:\Perforce\StoryEngine_Rick\StoryEngine\Library\ScriptAssemblies\ThirdParty.Runtime.dll', exception Failed to resolve TPoint
    (a half dozen times) on code that used to compile fine. I've tried rebuilding assets, deleting my library and rebuilding, etc. and it doesn't help.
     
  7. sandbox_dds

    sandbox_dds

    Joined:
    Nov 29, 2017
    Posts:
    3
    I'm facing the same problem on Unity 2021.3.1f1 and 2021.3.2f1, the build process is failing when I try to build for Android. When I build the project on Unity 2021.2.17f1 this problem don't occurs.

     
    Last edited: May 18, 2022
  8. LeoThurler

    LeoThurler

    Joined:
    Jan 5, 2016
    Posts:
    3
    Hello @JoshPeterson,

    Do you have some news about this problem?
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,038
    Our QA team has not yet investigated it. I've raised its priority internally though, so they will look at it soon.
     
  10. billykater

    billykater

    Joined:
    Mar 12, 2011
    Posts:
    313
    @JoshPeterson This issue (or a really similar one) also happens without IL2CPP. All that is needed for us is a specific set of generics usage while building for win64. Our case number is 1426750. For us this happened while trying to upgrade from 21.2.13f1 to 21.3.2f1
     
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,038
    Thanks, that is good to know. I've linked the two bug reports internally.
     
  12. ShenKang4181

    ShenKang4181

    Joined:
    Aug 13, 2019
    Posts:
    8
    upload_2022-5-31_9-53-50.png
    I made the same mistake after upgrading the unity version,
    These are the 10 mistakes every time,
    The timing is addressable packaging and build
     
  13. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,844
  14. DiacPaulAlexandru

    DiacPaulAlexandru

    Joined:
    Oct 20, 2020
    Posts:
    3
    Hello we are facing same issue upload_2022-5-31_10-14-57.png
    Is there any workaround for this?
     
  15. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,038
    It looks like our QA team has processed the bug report, and it is assigned to a development team to correct. I don't know about a workaround, unfortunately, but I have mentioned this forum thread to the development team, so they will likely follow up with details.
     
    DiacPaulAlexandru likes this.
  16. ShenKang4181

    ShenKang4181

    Joined:
    Aug 13, 2019
    Posts:
    8
    I deleted these codes and everything went back to normal. Take a look, it may help you.
     

    Attached Files:

  17. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,844
    It'd be great to get those details. Mostly wondering if the bug is likely to be an easy fix, or if we should rewrite a bunch of our code to be less generic.
     
  18. billykater

    billykater

    Joined:
    Mar 12, 2011
    Posts:
    313
    Seems that at least for us (without IL2CPP) the bug is fixed in 2021.3.4f1
    • Scripting: Fixed a case where the type of generic fields inside generic classes would fail to get resolved when building the project. (1415422)
     
  19. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,038
    A development team is investigating the bug report now, but I'm not sure of the status of the investigation. I'll as them to respond here with details when they have some.
     
  20. rarepop99

    rarepop99

    Unity Technologies

    Joined:
    Sep 5, 2019
    Posts:
    52
    It's something we need to fix, for sure. I will be investigating/fixing this as I might have regressed some behaviour with what @billykater posted above :/
     
  21. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,844
    It seems like 2021.3.4f1 might have fixed this issue! We're at least not getting any errors on PC on either mono or il2cpp, will be testing consoles next
     
  22. rarepop99

    rarepop99

    Unity Technologies

    Joined:
    Sep 5, 2019
    Posts:
    52
    Yeah I also pushed a fix as well, but glad it (seems) to have fixed it :)

    We have a bunch of seemingly related bug reports that came in recently, I will test the status of them after the fix to see if it's something we need to address, still :D
     
    goncalo-vasconcelos likes this.
  23. billykater

    billykater

    Joined:
    Mar 12, 2011
    Posts:
    313
    For anyone wondering if they want to update to this version. Be advised that https://issuetracker.unity3d.com/is...is-overlapping-in-the-inspector-when-expanded is back. So if you have a lot of arrays of serialized classes in it wait for this to be fixed (again ...)

    [Edit]
    Seems the actual issue is linked under known issues https://issuetracker.unity3d.com/is...n-for-arrays-that-use-custom-property-drawers for those that want to track when it is fixed.
     
    Last edited: Jun 8, 2022
  24. mdj_unity

    mdj_unity

    Joined:
    Aug 11, 2021
    Posts:
    1
    @rarepop99 Will the fix come out in 2020 LTS ?
    We are currently running 2020.3.35f1 and are having the same issues
     
  25. rarepop99

    rarepop99

    Unity Technologies

    Joined:
    Sep 5, 2019
    Posts:
    52
    2020.3.36f1 :)
     
    ShenKang4181 and LeoThurler like this.
unityunity