Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by Jessy · Aug 29, 2010 at 02:36 PM · editor-scriptingnamespace

How can you access scripts in a folder called "Editor" from elsewhere?

For example, access this:

class InsideEditorFolder {
    public static void DoItToIt () {}
}

with this:

public class OutsideEditorFolder : MonoBehaviour {
    [ContextMenu("Context Menu Item")] void ContextMenuItem () {
        InsideEditorFolder.DoItToIt();
    }
}

Here is a real-world example project (probably won't work right unless you have the Unity 3 beta). I assume this is an issue of namespaces, but I don't really know anything about that subject yet.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Lucas Meijer 1 · Aug 29, 2010 at 04:02 PM

As of Unity3 you can actually do this. However, the editorscript will not be available when you publish to your target platform, so it is up to you to properly use #if UNITY_EDITOR #endif blocks to make sure that code only gets included when you run the game in the editor.

I'm pretty sure that in order for it to work, you need to make sure the editorscript is in an earlier "compilation phase" than the runtime script. Putting your editorscript in Plugins/Editor/MyEditorScript.cs should do the trick. that said, you can also do whatever you want to do in your editorscript in your runtime script. You can just access UnityEditor.* and do whatever you feel like, again with the same caveat that it will not work when you publish, so you need to use the ifdefs to make sure the code is not included in builds.

Comment
Add comment · Show 3 · 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 Jessy · Aug 30, 2010 at 10:36 PM 0
Share

That's good information, but not helping me. The entire point of the question is to organize things how I want. Your solution just involves making the organization even worse, and in fact, nonsensical, as it's not a plugin. Not to say it's something wrong with your methods, it's just sad that some weird workaround has to be undertaken.

avatar image Lucas Meijer 1 ♦♦ · Aug 31, 2010 at 01:42 PM 0
Share

You don't have to put it in the Plugins folder, you can also just have it in the same folder as your gamescript, as long as you properly use #if UNITY_EDITOR around the parts that talk to editor api

avatar image Jessy · Sep 01, 2010 at 12:13 AM 0
Share

I know that it can be in the same folder; that's what I did in the example to which I linked. But I don't want it there. I want it to go a folder called Editor. Some things, like custom Inspectors, HAVE to go into a folder called Editor. So considering those folders are already created, I should be able to throw whatever I want in there, as they have such a useful name.

avatar image
0

Answer by TowerOfBricks · Aug 29, 2010 at 02:56 PM

Hi Jessy

Well, you can't.

The scripts inside the "Editor" folder are supposed to be used only in the editor (like custom editors, custom windows, etc etc). Due to the compilation order (the editor folder scripts are compiled last), you can't access those scripts from outside the editor folder.

It might be possible that you could pass a delegate to the script outside the editor folder first, and then make that script call it when needed.

It might also be possible that you could just define the ContextMenu in the editor script, or that you could call:

[MyOtherScript.ContextMeny ("Random")]

But I haven't tried that though.

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 Jessy · Aug 29, 2010 at 03:29 PM 0
Share

Obviously, a context menu is only going to be used in the Editor, so there needs to be a way to connect context menus with other scripts. I see no logic in allowing contextual menus to be present on $$anonymous$$onoBehaviors, and they should be done through some other means (not via a custom editor, because there should be an option to keep the default editor and just alter the contextual menu.)

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

No one has followed this question yet.

Related Questions

Is there a way to see namespaces in Editor ? (complete class name) 0 Answers

Detecting scene save - replacement for AssetModificationProcessor.OnWillSaveAssets 1 Answer

A weird issue in Unity related to scripts and Editor. 1 Answer

Visual Studio Setup 2 Answers

How to detect if unity build scene for target platform or editor player 2 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