0

When building the project, an error appears that "The type or namespace name 'Animations' does not exist in the namespace 'UnityEditor'", but Visual Studio does not show errors and all the libraries are connected, I found a solution how to upload the dll file to the Plug-in but could not find where to download dll file UnityEditor. I want to use the Animator Controller in a unity editor.

using UnityEngine;
using UnityEditor.Animations;

public class SkinSetter : MonoBehaviour
{
    public Animator anim;

    public AnimatorController skin1;
    public AnimatorController skin2;
    public AnimatorController skin3;
    public AnimatorController skin4;
    public AnimatorController skin5;
    public AnimatorController skin6;
    public AnimatorController skin7;
    public AnimatorController skin8;



    private void Start()
    {
        SetSkin(PlayerPrefs.GetInt("SkinSelect"));
    }

    public void SetSkin(int ID)
    {
        switch (ID)
        {
            case 1:
                anim.runtimeAnimatorController = skin1;
                break;
            case 2:
                anim.runtimeAnimatorController = skin2;
                break;
            case 3:
                anim.runtimeAnimatorController = skin3;
                break;
            case 4:
                anim.runtimeAnimatorController = skin4;
                break;
            case 5:
                anim.runtimeAnimatorController = skin5;
                break;
            case 6:
                anim.runtimeAnimatorController = skin6;
                break;
            case 7:
                anim.runtimeAnimatorController = skin7;
                break;
            case 8:
                anim.runtimeAnimatorController = skin8;
                break;
        }

    }

}
8
  • UnityEditor is a namespace specific for Unity Editor internal stuff and custom editor scripts ... it is not available in a build so you don't want to use anything from it in a MonoBehaviour! Commented Jun 18, 2020 at 6:11
  • Ok, and how do I fix it, I need to put the AnimatorController in an array Commented Jun 18, 2020 at 6:17
  • erase using UnityEditor.Animations; Commented Jun 18, 2020 at 6:18
  • Every script using UnityEditor should be inside Editor folder, is your case? Commented Jun 18, 2020 at 6:19
  • 1
    @Lotan that's recommended but not necessary ... you can also exclude them from the build using #if UNITY_EDITOR ... Commented Jun 18, 2020 at 6:43

1 Answer 1

8

As mentioned you do not want to use anything related to UnityEditor in your MonoBehaviour at least not in code that shall be executed in your app later.

It is only used to implement some special behaviors while working within the Unity Editor, mostly for custom Inspectors.

This namespace is completely stripped of during the build. So you will get compiler errors when building.


You should make your fields rather of type RuntimeAnimatorController

public RuntimeAnimatorController skin1;
...

and remove any using statement that contains UnityEditor from your script.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.