Search Unity

ScriptableObject works fine in Editor, but I cannot build my application because of it

Discussion in 'Scripting' started by Avalin, Sep 4, 2020.

  1. Avalin

    Avalin

    Joined:
    Oct 12, 2018
    Posts:
    98
    My entire ScriptableObject:
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEditor.Animations;
    3. using UnityEngine;
    4.  
    5. [CreateAssetMenu(fileName = "TileEntityData", menuName = "Room/Tile Entity Data")]
    6. public class TileEntityData : ScriptableObject
    7. {
    8.     public Sprite sprite;
    9.     public AnimatorController animationController;
    10.     public string nameKey;
    11.     public string descriptionKey;
    12.     public new string name;
    13.     public string description;
    14.     public bool isBlocking;
    15.     public List<string> TileEntityModifiers = new List<string>();
    16.     public int sortOrderRelativeToTile;
    17.     public Vector3 positionRelativeToTile;
    18. }
    When I attempt building my application:
    UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
    at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x0027c] in <3b1af5075b0340cfb428dfcef292b2ea>:0
    at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <3b1af5075b0340cfb428dfcef292b2ea>:0
    UnityEditor.EditorApplication:Internal_CallGlobalEventHandler()

    Assets\Scripts\Interactables\TileEntityData.cs(2,19): error CS0234: The type or namespace name 'Animations' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)

    Assets\Scripts\Interactables\TileEntityData.cs(9,12): error CS0246: The type or namespace name 'AnimatorController' could not be found (are you missing a using directive or an assembly reference?)

    Error building Player because scripts had compiler errors


    So yeah, everything runs smooth when I run the program, no compile errors.
    Am I not allowed to use animations or am I missing something?
    This is the first time I use ScriptableObject, so pardon my obliviousness
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    The UnityEditor namespace is not available in builds, if your runtime code depends on it you will have to look for other solutions. If not, you can wrap the code in #if UNITY_EDITOR /.../ #endif and the code will be excluded from builds.
     
    Xepherys and Avalin like this.
  3. Avalin

    Avalin

    Joined:
    Oct 12, 2018
    Posts:
    98
    Ah that was the culprit - I thought it said UnityEngine and not UnityEditor.
    I fixed it by changing AnimatorController to RuntimeAnimatorController :) Thank you!
     
    digitalp1985 and Xepherys like this.