The type or namespace name 'AddressableAssets' does not exist in the namespace 'UnityEditor' (build)

Full Error:
Assets/Scripts/AddressablesManager.cs(5,19): error CS0234: The type or namespace name ‘AddressableAssets’ does not exist in the namespace ‘UnityEditor’ (are you missing an assembly reference?)

Edit: Problem happens now only during the build process. I added Tests

Description:
I am using Addressables, had my implementation, everything worked, however, once I added tests, problems started to occur. I added NSubstitute from this tutorial:

This required me to used ADRs (Assembly Definition Reference(s)). Noticed my none test code was now broken. I found this thread, which tells that you must add references manually:

So I created an ADR on my Scripts folder and added the needed references for my project:

  • Unity.Addressables
  • Unity.ResourceManager
  • Unity.InputSystem
  • Unity.XR.Interaction.Toolkit
  • Unity.ScriptableBuildPipeline
  • Unity.Addressables.Editor (Edit: added later and solves the Play/Edit mode errors.)

Even then I still get the error above. What am I missing?

Thanks!

Solution:

  • Make sure not to use Editor namespaces are they are not available during runtime.

  • You can reorganize your Scripts with these under Editor folder(s) and add the dependencies into its assembly reference.

  • Remove Editor assembly references from your main scripts, usually your Scripts folder.

  • If using AddressableGroups, make sure to read documentation on how to access them during runtime. Do know that as of version 1.18, groups are not available at runtime, they are converted to asset bundles. But maybe you don’t want to load as an asset bundle and just a few assets or so. My workaround was to create a json config file to load their keys at runtime, more info here: Using Addressables at runtime | Addressables | 1.18.19.

  • I recommend creating a build script and accessing settings/groups, you’ll need to implement this: Unity - Scripting API: Build.IPreprocessBuildWithReport.OnPreprocessBuild

  • For PlayMode use

  • InitializeOnLoadAttribute* and follow this: Unity - Scripting API: EditorApplication.playModeStateChanged

  • If using AddressableSettings do know that is part of Editor namespace so they are not available at runtime! (As of version 1.18). Again, I avoided using them with the config file.

Happy coding!

Setup:
macOS Big Sur 11.6 (20G165)
Unity 2020.325f1
Visual Studio Code 1.63.2
OmniSharp 1.23.17
Debugger for Unity 3.0.2
Mono JIT compiler version 6.12.0.122
.NET 3.1.416

Assembly Definitions:

Scripts: Contains all regular scripts.

Editor: Contains all editor scripts.

PlayTests: Contains tests scripts for Play Mode.

package.json:

{
"dependencies": {
"com.unity.addressables": "1.18.19",
"com.unity.collab-proxy": "1.15.7",
"com.unity.ide.rider": "2.0.7",
"com.unity.ide.visualstudio": "2.0.12",
"com.unity.ide.vscode": "1.2.4",
"com.unity.render-pipelines.universal": "10.7.0",
"com.unity.test-framework": "1.1.30",
"com.unity.testtools.codecoverage": "1.1.1",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.4.8",
"com.unity.toolchain.macos-x86_64-linux-x86_64": "1.0.0",
"com.unity.ugui": "1.0.0",
"com.unity.xr.interaction.toolkit": "2.0.0-pre.6",
"com.unity.xr.management": "4.2.1",
"com.unity.xr.oculus": "1.11.2",
"com.unity.xr.openxr": "1.3.1",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.umbra": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
}

Package Manager:

Found the solution, turns out there’s more than one reference to add from Addressables. I needed to add Unity.Addressables.Editor as well! So watch out, there’s more than one Addressable reference to be used depending on your code implementation.

I literally spent hours before posting and few minutes after posting I decided to try adding the other ones and Editor module worked for me!

Edit:
Final directives look like this for me:

Edit #2: Seems the problem is back when I try to build for Android. Not sure what to do at the moment :frowning:

Help!

Well, seems my naiveness got the better of me. So it seems that UnityEditor namespace are only meant to be used in Editor Mode. This seems to carry over into any “Editor” like namespace. So these won’t be available at runtime. With that I had to make changes:

  • I reorganized all my Editor scripts to go under Editor, I had marked them with #if UNITY_EDITOR but just seems cleaner to have them in the appropriate folder.

  • Removed any dependencies to UnityEditor from my regular non-Editor scripts, in this case my need was to access Addressable Groups. I was using AddressableSettings, which are part of Editor package. Also, apparently groups and settings are not available at runtime. Groups are converted into Asset Bundles. In my case I just built a custom script to keep references in a config file. I agree that groups need to be conserved and be used during runtime, in all honestly why would you define them and just take them away at runtime?! Anyhow… I got the info from these:

  • How can I use AddressableAssetGroups in runtime? (Discussion about the need)

  • Using Addressables at runtime | Addressables | 1.18.19 (Look for the version you are using, modify it at the address bar. Documenters please allow a drop-down for this in the future, thanks!)

With all that out of the way my project built! But Alas! A new problem occurred, I was able to sideload to my Quest 2, but the app would not show up. For that I had to manually uninstall the app via adb:

  • adb uninstall <your.package.name>

You can find your current package name under File>Build Settings>Player Settings>Player>Android>Other Settings>Identification>Package Name. More descriptive (Using Unity 2020.3 at the time of this post):

  • File>Build Settings.
  • Then assuming you already switched to Android, click on Player Settings…
  • Under Player Select Android platform (Android icon).
  • Then got Other Settings under Identification you will see Package Name.

Hope this helps someone out there, because I spent unnecessary hours on it so you don’t have to :wink:

So we just have to put Editor specific files in the ./Editor folder