Search Issue Tracker

Fixed

Fixed in 2021.3.23f1, 2022.2.14f1, 2023.1.0b12, 2023.2.0a9

Votes

0

Found in

2020.3.41f1

2021.3.13f1

2022.1.22f1

2022.2.0b13

2023.1.0a18

2023.2.0a1

Issue ID

UUM-18689

Regression

No

[IL2CPP] Using a Service Locator to retrieve a static list of classes doesn't work with IL2CPP in a built Player

--

-

Steps to reproduce:
1. Open the attached user's project "TapTapTap.zip"
2. Make sure to install this package https://github.com/Studious-Games/SingletonSystem
3. Build the "Scenes/MainGame.unityscene" Scene
4. Press the white dot to count the score
5. Observe the score not going up
6. Navigate to and open "Assets/Scripts/Spawner.cs", comment out 84'th line and uncomment the 81'st line
7. Repeat step 3
8. Observe that the score goes up

Expected results: "SingletonLocator.Get<ScoreManager>().DotsClicked++" works with IL2CPP scripting backend
Actual results: "SingletonLocator.Get<ScoreManager>().DotsClicked++" does not work with IL2CPP scripting backend

Reproducible on: 2020.3.41f1, 2021.3.13f1, 2022.1.22f1, 2022.2.0b13, 2023.1.0a18

Notes:
-The difference is that "SingletonLocator.Get<ScoreManager>().DotsClicked++" is retrieved from a static list of classes, via a Service Locator, whereas "ScoreManager.Instance.DotsClicked++" is not.
-Issue reproduces only on IL2CPP with both Windows standalone and Android platforms

  1. Resolution Note (fix version 2023.2.0a9):

    We have removed throws of exceptions in setters of Attribute classes in the il2cpp aot profile.

    However there has been a behavioral change in Unity that causes a similar problem. https://issuetracker.unity3d.com/issues/findobjectsoftype-doesnt-find-objects-when-invoked-in-a-method-with-runtimeinitializeonloadmethod-attribute-and-loadtype-of-beforesceneload

    The following code needs updated...
    https://github.com/Studious-Games/SingletonSystem/blob/master/Runtime/SingletonInitialisation.cs#L13

Comments (1)

  1. BillHolmes

    Nov 07, 2022 22:01

    There is a problem in the il2cpp class libraries that I am looking into fixing. The type `System.Configuration.SchemeSettingElementCollection` fails to load its attributes due to an error we have in our implementation of `ConfigurationCollectionAttribute`

    The code from SingletonSystem is scanning all of the assemblies and all the types in the system, looking for the SingletonAttribute. When this scan encounters the `SchemeSettingElementCollection` type, that is causing this bug.

    You can work around this issue (and make the code more efficient) by filtering out assemblies, or types that you know that you do not care about.

    Here is simple suggestion to help workaround the problem while you wait for the fix.

    https://github.com/Studious-Games/SingletonSystem/blob/5325b5d678e98b8388feae40b808fbd25aecaa64/Runtime/SingletonInitialisation.cs#L21

    IEnumerable<Type> types = AppDomain.CurrentDomain.GetAssemblies().Where(a => a != typeof(System.Uri).Assembly).SelectMany(assembly => assembly.GetTypes().Where(type => type.GetCustomAttributes(typeof(SingletonAttribute), true).Length > 0));

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.