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
0
Question by viru · May 01, 2012 at 04:24 AM · editorgamewindowplaying

Accessing Editor Window from Game Code

I have a custom editor window which I made in unity 3.5. I wanna know if there's any way I could open up that window from the Game Code when the Game is Playing. I have read through the blogs but I cudn't find anything that allows me to access my editor script from the game code.

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

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · May 01, 2012 at 04:30 AM

In general it isn't possible since the UnityEditor namespace isn't available at runtime. If you use anything from there you can't build your game. However you can use platform dependent compilation to open your editor window. Of course this will only work when you play your game inside the editor. When you build your game the code between #if and #endif will be automatically removed.

 //C#
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.A))
     {
         #if UNITY_EDITOR
         UnityEditor.EditorWindow.GetWindow<YourEditorWindow>();
         #endif
     }
 }

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 viru · May 01, 2012 at 05:19 PM 0
Share

Yes I tried had this approach but Unity would still throw "The type or namespace name '$$anonymous$$yEditor' could not be found". I also tried keeping both the editor script and the monobehaviour script in the same namespace but that didn't work also adding a namespace wouldn't let me open my editor in the editor mode itself. Am I supposed to keep this script in a "Editor" folder ?? Wat am I missing ?

avatar image yoyo · Aug 19, 2013 at 11:35 PM 1
Share

You could also put a delegate (callback) in your game code, which editor code can then set the delegate to call another editor method.

avatar image shawnblais yoyo · Oct 21, 2020 at 03:33 AM 0
Share

Thanks for this idea, great inversion.

 public class ScreenshotUtility : EditorWindow
 {
    private void OnEnable(){
       GameCam$$anonymous$$anager.CaptureScreenDelegate += RenderScreenshot;
    }
 }
 ...
 class GameCam$$anonymous$$anager extends $$anonymous$$onoBehavior {
 
    public static Action CaptureScreenDelegate;
 
    public void CaptureScreen() => CaptureScreenshotDelegate?.Invoke();
 
 }

No need for compile flags, and fails gracefully in release build.

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

Game window size from editor window in editor mode 1 Answer

Unity game window size 1 Answer

How to build an editor window with a treeview widget? 4 Answers

Is there a way to manually resize the controls inside an editor window at runtime? 1 Answer

When Playing Game I cannot see Grass from Terrain 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