Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
1
Question by Ryaurezh · Dec 30, 2015 at 04:48 AM · c#erroreditor-scripting

Why can't some of my scripts see other scripts or namespaces?

I'm creating a custom editor for an item system, and for some reason, some of my scripts cannot access other scripts or namespaces. What would be causing this?

 // This script can access any other script
 // File located in Assets/ItemSystem/Scripts/Editor/ISEditor
 namespace ItemSystem.Editor {
    public class ItemDatabaseType<D,T>  where D : ItemDatabase<T> where T: ISObject
    {
       ISObject item;  // Works fine
       
    }
 }
 
 
 // This script's access is very limited.  Can't access the above namespace 
 // or script (even if script is in same namespace).
 // File located in: Assets/ItemSystem/Scripts/ISObjects
 using ItemSystem.Editor   // Doesn't work 

 namespace ItemSystem {
    public class ISObject 
    {
        OtherISObject otherItem;   // Works fine
        ItemSystem.OtherISObject otherItem2; // Works fine

        // These do not work:
        ItemDatabaseType<DatabaseScript, ISObject > idt; 
        ItemSystem.Editor.ItemDatabaseType<DatabaseScript, ISObject > idt2;
           // Error: The type or namespace could not be found,
           // though DatabaseScript and ItemScript are.
    }
 }


 // This script has no namespace.  It can access the ItemSystem namespace, but not ItemSystem.Editor
 // File located in Assets/ItemSystem/Scripts/DatabaseScripts
 public class ItemDatabase<T> : ScriptableObject where T: ItemSystem.ISObject {
    ItemSystem.ISObject item;   // Works
    ItemSystem.Editor.ItemDatabaseType<DatabaseScript, ISObject> item2;   // Doesn't work
 }




Comment
Add comment · Show 3
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 NGC6543 · Dec 30, 2015 at 06:46 AM 0
Share

how about declare it before? like this :

 using UnityEngine;
 using System.Collections;
 using TestNameSpace;    //FIX$$anonymous$$E comment here to see the change below
 using TestNameSpace.SubNameSpace;    //FIX$$anonymous$$E comment here to see the change below
 
 namespace TestNameSpace{
     public class TestClass{
         int i;
         public TestClass(){
             i = 1;
         }
     }
 }
 namespace TestNameSpace.SubNameSpace{
     public class SubTestClass{
         int i;
         public SubTestClass(){
             i = 2;
         }
     }
 }
 
 public class Test : $$anonymous$$onoBehaviour {
 
     TestClass testClass;        //see change here
     SubTestClass subTestClass;    //see change here
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 
avatar image Ryaurezh NGC6543 · Dec 31, 2015 at 02:59 AM 0
Share

I did initially test that, and it didn't work. As I stated in the accepted answer, the problem was caused by scripts being placed in an "Editor" folder. If "SubNameSpace" is only referenced in the "Editor" folder, then it doesn't exist; and if it is used outside of the folder, then only the files outside are visible. So far, there seems to be no way to access Editor scripts from the outside. If there is code specific to the Editor, then you can use #if UNITY_EDITOR & #endif. The two issues with that are 1) You have to put these two lines around every chunk of code that is only used by the Editor, and 2) I don't know if the code is still compiled (just not used) by Unity in the final build. For more information, check out: http://docs.unity3d.com/$$anonymous$$anual/SpecialFolders.html http://docs.unity3d.com/$$anonymous$$anual/ScriptCompileOrderFolders.html

 public class TestClass {
     void Some$$anonymous$$ethod() {  }
 
 #if UNITY_EDITOR    // Code used only if Editor is present
     void EditorOnly$$anonymous$$ethod() {  }
 #endif
 }
avatar image NGC6543 Ryaurezh · Dec 31, 2015 at 03:20 AM 0
Share

I think preprocessor directives strips codes out, so the codes does not being compiled at all when the build happens, isn't it? And the Editor-only scripts should not be included to the final build, so using #if UNITY_EDITOR is necessary and I didn't find it annoying.

2 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by Ryaurezh · Dec 30, 2015 at 06:58 AM

I figured it out. The issue is caused by placing some of my scripts in a folder called "Editor", which allows easy access to the UnityEditor, plus they are not included in the final build. The downside is that those scripts are not detected by others outside of the folder because Unity compiles them last; so as far as other scripts are concerned, they don't exist.

Comment
Add comment · Show 1 · 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 NGC6543 · Dec 30, 2015 at 07:02 AM 0
Share

Oh that's a nice info. Thanks for sharing it!

avatar image
1

Answer by BranchOffGameStudio · Jan 05, 2018 at 01:39 AM

I had the same issue. My Editor scripts were not able to recognize other script's/namespaces outside of the Editor folder. In order to fix I did the following:

  1. Move the editor scripts out of the editor folder into a folder with the rest of my scripts.

  2. Added the namespace to my editor scripts

  3. Closed monodevelop.

  4. Moved my editor scripts back into the Editor folder.

  5. Opened mono and built the project.

Now my project has namespaces for my Scriptable Objects, MonoBehaviours and Editor Scripts! Monodevelop can be fickle sometimes, but a little bit of persistence and toying can work to your advantage.

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Error: Unable to load the icon: 'CustomEditorWindow'. (Custom Scene View) 1 Answer

Im having an issue with a custom editor script pausing the whole editor with the little applicaton.message? 1 Answer

Hey guys, im starting do make a RPG game and in the Level system script(I called it "PlayerStatsController") i have an error: Parser Error : Unexpected symbol `public'. My script above: 1 Answer


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