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:




