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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Resolved Failed to compile player scripts / SBP Error when building Addressables.

Discussion in 'Addressables' started by JJNoguera, Sep 9, 2020.

  1. JJNoguera

    JJNoguera

    Joined:
    May 12, 2019
    Posts:
    5
    For a while now, when I try to build Addressables it give me both "Failed to compile player scripts" and "SBP Error" and not build them. They work fine in Play Mode in Editor, but if I try to build the game I can't because this errors show up. I tried looking for a way to solve this but I didn't a solution.

    The first time I try to build them everytime I open Unity it show me the "API Upgrade Required" window:

    updateRequired.jpg

    Whatever I choose, it throws this errors:

    SBPError.jpg

    Things I tried to solve this:
    - Upgrading Addressables Package from 1.8.4 to 1.8.5 and 1.15.1
    - Cleaning everything with the "Clean Build" button in "Addressables Group" window.
    - Removing and reinstalling the Addressables Package.
    - Removing the Package, deleting the "AddressablesAssetsData" folder, reinstalling it and reassign every address to every asset.

    Anyone knows why this happens? Thanks in advance.
     
    Last edited: Sep 9, 2020
  2. LuGus-Jan

    LuGus-Jan

    Joined:
    Oct 3, 2016
    Posts:
    169
    I see the line
    Failed to compile player script
    being in your screenshot multiple times. Addressables fail to build when they detect compile errors. Most likely, you have some pieces of code like the following:

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. // Code that only works in editor
    3. #else
    4. // Code that only works in build
    5. #endif
    Now, while playing in editor, only the first block of code is used and compiled, but when you make a build, the second block is used instead. The compiler can't process that second block in editor, since it's not meant to run in editor. So if any errors are in there, they only show up when you make an actual build (and creating Addressables bundles is a form of making a build.)
     
  3. JJNoguera

    JJNoguera

    Joined:
    May 12, 2019
    Posts:
    5
    I ended up solving it by changing "Api Compatibility Level" from .NET 2.0 to .NET4.x, but now for some reason any sprite coming from a sprite sheet is just invisible.

    Thanks for the help.
     
  4. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    This is not what causes that error; I have no compile errors in editor or on the phone. Addressables simply shows me these
    Errors on iOS only, for no reason. It compiles fine on android and WebGL.
    This seems like a bug.
     
    Gasimo likes this.
  5. FaithlessOne

    FaithlessOne

    Joined:
    Jun 19, 2017
    Posts:
    264
    I also came across this error in Unity 2022.3 using Addressables 1.21.12, also tested with 1.21.18. Addressables seem to cause some weird technical issues in Unity.

    This was the error I got when building my project:
    upload_2023-10-23_7-32-13.png

    When observing the console while building the project I noticed that there was another error shown for a short time in the console, but was removed when the final error arrived. Really great by the way for hiding the real error at the end:
    upload_2023-10-23_7-35-37.png

    While the project compiled and worked fine in the Unity Editor the build failed. Line 4 and 9 caused the issue and were referred by the CS0165 errors in the console:
    Code (CSharp):
    1. Assert.IsTrue(dummyTable.TryGet(dummyEntity, out var dummyByEntity));
    2. Assert.AreEqual(slot.Id, dummyByEntity.PureDummy.DummyId);
    3. Assert.AreEqual(slot.SlotIndex, dummyByEntity.PureDummy.SlotIndex);
    4. this.CheckItem(dummyByEntity);
    5.  
    6. Assert.IsTrue(dummyTable.TryGet(slot, out var dummyBySlot));
    7. Assert.AreEqual(slot.Id, dummyBySlot.PureDummy.DummyId);
    8. Assert.AreEqual(slot.SlotIndex, dummyBySlot.PureDummy.SlotIndex);
    9. this.CheckItem(dummyBySlot);
    This is fully correct C# 9 code. I uninstalled the Addressable package to check whether the issue was really caused by this package and yes the error was gone after removing the package.

    I changed the code to make it compatible to C# 7.2, but still had to add the default initializer:
    Code (CSharp):
    1. DummyListingItem dummyByEntity = default;
    2. Assert.IsTrue(dummyTable.TryGet(dummyEntity, out dummyByEntity));
    3. Assert.AreEqual(slot.Id, dummyByEntity.PureDummy.DummyId);
    4. Assert.AreEqual(slot.SlotIndex, dummyByEntity.PureDummy.SlotIndex);
    5. this.CheckItem(dummyByEntity);
    6.  
    7. DummyListingItem dummyBySlot = default;
    8. Assert.IsTrue(dummyTable.TryGet(slot, out dummyBySlot));
    9. Assert.AreEqual(slot.Id, dummyBySlot.PureDummy.DummyId);
    10. Assert.AreEqual(slot.SlotIndex, dummyBySlot.PureDummy.SlotIndex);
    11. this.CheckItem(dummyBySlot);
    After that the build run successful again with Addressables included.

    Addressables seems half-baked to me when fine C# 9 code causing failed bulds in Unity. I would like to remove the package instantly from my project after this experience. I also never wanted to use Addressables because of not even being compatible to other Unity Packages like UIToolkit. Unfortunately the Localization package uses Addressables as dependency. Next time I try to find a alternative for Localization to get rid of Addressables.
     
    Last edited: Oct 23, 2023
  6. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    285
    It's not valid C# because of the semantics of the Assert.IsTrue call. It's marked with [Conditional("UNITY_ASSERTIONS")] meaning that if the symbol UNITY_ASSERTIONS is not present when your assembly is being compiled, the entire call to Assert.IsTrue and the evaluation of any arguments you may pass to it don't exist. The variables are still considered valid, but since your initial assignment is known not to happen at compile time, the variable will be uninitialized at the first access. You can check the below code with modern .NET to see for yourself.
    Code (CSharp):
    1. using System.Diagnostics;
    2.  
    3. var dict = new Dictionary<string, string>();
    4. Test(dict.TryGetValue("", out string v));
    5. // This will error out if none of the [Conditional] target symbols on the method exist at compile time
    6. Console.WriteLine(v);
    7. [Conditional("NEVER")]
    8. //[Conditional("NET7_0_OR_GREATER")]
    9. static void Test(bool condition)
    10. {
    11. }
    Generally, you're not supposed to put anything (important) that has side effects inside such conditional calls, since they effectively erase whatever happens inside them when the symbol isn't defined.

    Logs disappearing: check to make sure the Console view is not set to Clear on Build / Recompile, one of which are probably the culprit.
     
    FaithlessOne likes this.
  7. FaithlessOne

    FaithlessOne

    Joined:
    Jun 19, 2017
    Posts:
    264
    Thanks for hinting into that direction. I changed my code accordingly. But still strange that the orginal code will be built successfully without Addressables package included.

    I already tried removing the Clear on Recompile and Clear on Build options in the Console without any success. Relevant errors are only showing during build and not at the end.