Home > front end >  UnityEditor.SceneAsset class not accessible in build
UnityEditor.SceneAsset class not accessible in build

Time:11-08

I am new to unity addressables and would like to load a scene with an AssetReference. To enforce AssetReferences being a scene, I created the following class in a utility assembly:

using System;
using UnityEngine;
using UnityEngine.AddressableAssets;

[Serializable]
public sealed class SceneReference : AssetReferenceT<SceneAsset>
{
    public SceneReference(string guid) : base(guid) { }
}

JetBrains Rider then said SceneAsset had to be referenced from assembly: UnityEditor.CoreModule. I used its suggestion, and Rider automatically set up the assembly reference. Everything worked great, and indeed I could only drag scenes into a SceneReference field.

But everything broke down when I went to make a build. I get four errors:

1:Internal build system error. Backend exited with code 139.

2:Error building Player because scripts had compiler errors

3:Build completed with a result of 'Failed' in 11 seconds (11360 ms) UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

4:UnityEditor.BuildPlayerWindow BuildMethodException: 2 errors at UnityEditor.BuildPlayerWindow DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002ce] in /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPlayerWindowBuildMethods.cs:193 at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPlayerWindowBuildMethods.cs:94 UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

I have tried to manually locate assembly UnityEditor.CoreModule and reference it in my utility assembly's assembly definition asset but couldn't find it. It still works great in the editor but won't compile for a build. If anyone has a solution or at least knows why this isn't working, I would be most appreciative.

CodePudding user response:

SceneAsset indeed can not be in a build and only exists within the Unity Editor. It is a special case of an asset that only exists in editor since later on in a build the scenes are handled completely different as runtime Scene.

The entire UnityEditor namespace is completely stripped of in a build.


For serialization the best option is usually to serialize and store the asset path and later use that for loading the scene.


you can still make scenes addressables though and load them via the usual more manual addressables route. See Addressables - Scene Loading.

  • Related