• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Dec 18, 2015 at 09:12 AM by Griffo for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by Griffo · Dec 17, 2015 at 07:46 PM · scripting problemeditornamespace

The type or namespace name `UnityEditor' could not be found

Hi,

I'm using the below CrossPlatformInputInitialize.cs script and when trying to build to iOS I get the following errors, how can I correct these errors? .. Thanks.

Assets/Plugins/StandardAssets/CrossPlatformInput/Scripts/CrossPlatformInputInitialize.cs(3,7): error CS0246: The type or namespace name UnityEditor' could not be found. Are you missing a using directive or an assembly reference? Assets/Plugins/StandardAssets/CrossPlatformInput/Scripts/CrossPlatformInputInitialize.cs(98,24): error CS0246: The type or namespace name BuildTargetGroup' could not be found. Are you missing a using directive or an assembly reference?

Assets/Plugins/StandardAssets/CrossPlatformInput/Scripts/CrossPlatformInputInitialize.cs(7,6): error CS0246: The type or namespace name InitializeOnLoad' could not be found. Are you missing a using directive or an assembly reference? Assets/Plugins/StandardAssets/CrossPlatformInput/Scripts/CrossPlatformInputInitialize.cs(7,6): error CS0246: The type or namespace name InitializeOnLoadAttribute' could not be found. Are you missing a using directive or an assembly reference?

 using System;
 using System.Collections.Generic;
 using UnityEditor;
 
 namespace UnityStandardAssets.CrossPlatformInput.Inspector
 {
     [InitializeOnLoad]
     public class CrossPlatformInitialize
     {
         // Custom compiler defines:
         //
         // CROSS_PLATFORM_INPUT : denotes that cross platform input package exists, so that other packages can use their CrossPlatformInput functions.
         // EDITOR_MOBILE_INPUT : denotes that mobile input should be used in editor, if a mobile build target is selected. (i.e. using Unity Remote app).
         // MOBILE_INPUT : denotes that mobile input should be used right now!
 
         static CrossPlatformInitialize()
         {
             var defines = GetDefinesList(buildTargetGroups[0]);
             if (!defines.Contains("CROSS_PLATFORM_INPUT"))
             {
                 SetEnabled("CROSS_PLATFORM_INPUT", true, false);
                 SetEnabled("MOBILE_INPUT", true, true);
             }
         }
 
 
         [MenuItem("Mobile Input/Enable")]
         private static void Enable()
         {
             SetEnabled("MOBILE_INPUT", true, true);
             switch (EditorUserBuildSettings.activeBuildTarget)
             {
                 case BuildTarget.Android:
                 case BuildTarget.iOS:
                 case BuildTarget.WP8Player:
                 case BuildTarget.BlackBerry:
                 case BuildTarget.PSM: 
                 case BuildTarget.Tizen: 
                 case BuildTarget.WSAPlayer: 
                     EditorUtility.DisplayDialog("Mobile Input",
                                                 "You have enabled Mobile Input. You'll need to use the Unity Remote app on a connected device to control your game in the Editor.",
                                                 "OK");
                     break;
 
                 default:
                     EditorUtility.DisplayDialog("Mobile Input",
                                                 "You have enabled Mobile Input, but you have a non-mobile build target selected in your build settings. The mobile control rigs won't be active or visible on-screen until you switch the build target to a mobile platform.",
                                                 "OK");
                     break;
             }
         }
 
 
         [MenuItem("Mobile Input/Enable", true)]
         private static bool EnableValidate()
         {
             var defines = GetDefinesList(mobileBuildTargetGroups[0]);
             return !defines.Contains("MOBILE_INPUT");
         }
 
 
         [MenuItem("Mobile Input/Disable")]
         private static void Disable()
         {
             SetEnabled("MOBILE_INPUT", false, true);
             switch (EditorUserBuildSettings.activeBuildTarget)
             {
                 case BuildTarget.Android:
                 case BuildTarget.iOS:
                 case BuildTarget.WP8Player:
                 case BuildTarget.BlackBerry:
                     EditorUtility.DisplayDialog("Mobile Input",
                                                 "You have disabled Mobile Input. Mobile control rigs won't be visible, and the Cross Platform Input functions will always return standalone controls.",
                                                 "OK");
                     break;
             }
         }
 
 
         [MenuItem("Mobile Input/Disable", true)]
         private static bool DisableValidate()
         {
             var defines = GetDefinesList(mobileBuildTargetGroups[0]);
             return defines.Contains("MOBILE_INPUT");
         }
 
 
         private static BuildTargetGroup[] buildTargetGroups = new BuildTargetGroup[]
             {
                 BuildTargetGroup.Standalone,
                 BuildTargetGroup.WebPlayer,
                 BuildTargetGroup.Android,
                 BuildTargetGroup.iOS,
                 BuildTargetGroup.WP8,
                 BuildTargetGroup.BlackBerry
             };
 
         private static BuildTargetGroup[] mobileBuildTargetGroups = new BuildTargetGroup[]
             {
                 BuildTargetGroup.Android,
                 BuildTargetGroup.iOS,
                 BuildTargetGroup.WP8,
                 BuildTargetGroup.BlackBerry,
                 BuildTargetGroup.PSM, 
                 BuildTargetGroup.Tizen, 
                 BuildTargetGroup.WSA 
             };
 
 
         private static void SetEnabled(string defineName, bool enable, bool mobile)
         {
             //Debug.Log("setting "+defineName+" to "+enable);
             foreach (var group in mobile ? mobileBuildTargetGroups : buildTargetGroups)
             {
                 var defines = GetDefinesList(group);
                 if (enable)
                 {
                     if (defines.Contains(defineName))
                     {
                         return;
                     }
                     defines.Add(defineName);
                 }
                 else
                 {
                     if (!defines.Contains(defineName))
                     {
                         return;
                     }
                     while (defines.Contains(defineName))
                     {
                         defines.Remove(defineName);
                     }
                 }
                 string definesString = string.Join(";", defines.ToArray());
                 PlayerSettings.SetScriptingDefineSymbolsForGroup(group, definesString);
             }
         }
 
 
         private static List<string> GetDefinesList(BuildTargetGroup group)
         {
             return new List<string>(PlayerSettings.GetScriptingDefineSymbolsForGroup(group).Split(';'));
         }
     }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
6
Best Answer

Answer by Jessespike · Dec 17, 2015 at 08:18 PM

Create a folder called "Editor" and move the script into it.

Read this: Unity Wiki -- Special Folder Names in your Assets Folder

  • The Editor folder name is a special name which allows your scripts access to the Unity Editor Scripting API. If your script uses any classes or functionality from the UnityEditor namespace, it has to be placed in a folder called Editor.

  • Scripts inside an Editor folder will not be included in your game's build. They are only used in the Unity Editor.

  • You can have multiple Editor folders throughout your project

  • Note: An Editor folder not located in another special folder can be placed/nested anywhere in the project. However, if it's in "Standard Assets", "Pro Standard Assets", or "Plugins", it must be a direct child of these folders. Otherwise, it will not get processed. For example, it's ok to have a path like "My Extension/Scripts/Editor", but if placed in a special folder, it must always be "Standard Assets/Editor/My Extension/Scripts", or "Pro Standard Assets/Editor/My Extension/Scripts", or "Plugins/Editor/My Extension/Scripts".

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Griffo · Dec 17, 2015 at 08:33 PM 0
Share

Thank you, that worked.

avatar image Claudioteles85 · Jun 03, 2017 at 12:30 AM 0
Share

$$anonymous$$oving all of the files into an Editor folder only exempts the scripts, which I need them to make the game work. How do I include my scripts in the Build so that they work in the game?

avatar image Bunny83 Claudioteles85 · Jun 03, 2017 at 09:20 AM 0
Share

You should not move all your files into an editor folder, only editor scripts. The script in question is an editor script.

Runtime scripts must not be inside an editor folder. Editor scripts must be inside an editor folder.

avatar image Anne-Pier Bunny83 · Nov 29, 2017 at 11:47 AM 0
Share

You could just use #if UNITY_EDITOR #endif around ''using UnityEditor'' and all parts in the code that require it.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

35 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Error CS0234: The type or namespace name `IActiveBuildTargetChanged' does not exist in the namespace `UnityEditor.Build'. Even after moving Editor folder. 4 Answers

Which is the namespace of the Joystick pack?,Which is the nameSpace of Joystick pack? 2 Answers

Event.pressure, does it work? 0 Answers

switching default text editor for Script editing 1 Answer

Can't change a variable inside the standard RigidbodyFirstPersonController 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges