Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
17
Question by fredpointzero · Aug 31, 2011 at 05:57 AM · editoreditor-scriptingstartstop

Start/Stop Playmode from editor script

Is it possible to Start / Stop the player in the editor from an editor script ?

Comment
Add comment · Show 1
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 Quatum1000 · Feb 29, 2016 at 04:27 AM 0
Share

Nonsens... Application.isPlaying is read only

9 Replies

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

Answer by Bunny83 · Aug 31, 2011 at 12:27 PM

Well, you can also set EditorApplication.isPlaying ;)

edit
Since there were complaints that "EditorApplication" can't be used in runtime scripts, here's how you can use it:

 //C#
 public static class AppHelper
 {
     #if UNITY_WEBPLAYER
     public static string webplayerQuitURL = "http://google.com";
     #endif
     public static void Quit()
     {
         #if UNITY_EDITOR
         UnityEditor.EditorApplication.isPlaying = false;
         #elif UNITY_WEBPLAYER
         Application.OpenURL(webplayerQuitURL);
         #else
         Application.Quit();
         #endif
     }
 }

Use this class from anywhere like this:

 AppHelper.Quit();


Comment
Add comment · Show 2 · 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 fredpointzero · Aug 31, 2011 at 12:30 PM 0
Share

That's even better, thanks !

avatar image dkozar · May 12, 2013 at 05:00 PM 2
Share

UT way of thinking surprises me over and over :)

In my way of thinking the "isX" property should be exclusively a getter.

And methods would be more appropriate for playing and stopping the app - like EditorApplication.stop();

But that's just me ;)

avatar image
8

Answer by Sigil · Aug 31, 2011 at 06:05 AM

I didn't see a direct call, but this worked in my editor script (dll to be particular):

 EditorApplication.ExecuteMenuItem("Edit/Play");
Comment
Add comment · Show 2 · 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 fredpointzero · Aug 31, 2011 at 07:55 AM 0
Share

Sounds good, I'll try this

avatar image fredpointzero · Aug 31, 2011 at 08:14 AM 0
Share

It worked ! Thanks you

avatar image
4

Answer by salat · Jul 26, 2013 at 05:50 AM

isPlaying work only in Editor scripts. in runtime use Debug.Break() to pause (not same as Debug.DebugBreak()) http://docs.unity3d.com/Documentation/ScriptReference/Debug.Break.html

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 Novack · Oct 15, 2016 at 03:50 PM 0
Share

Do you know what Debug.DebugBreak() does?

avatar image
2

Answer by Istador · Dec 18, 2013 at 09:42 PM

Debug.Break() is pausing the game, not stopping it.

Sadly you can't build a standalone version with "UnityEditor.EditorApplication.isPlaying = false;" in your code, because the class is unknown to the standalone version.

If you don't want to comment out the line everytime you want to produce a standalone build, you can use reflection to dynamically check for the class and change its property:

 using System;
 using System.Reflection;
 
 //only works in a standalone build, ignored in editor and webplayer
 Application.Quit();

 //only works in editor
 //casts "UnityEditor.EditorApplication.isPlaying = false;" dynamically using reflection
 Type t = null;
 foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) {
   t = a.GetType("UnityEditor.EditorApplication");
   if(t != null){
     t.GetProperty("isPlaying").SetValue(null, false, null);
     break;
   }
 }
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 Bunny83 · Dec 18, 2013 at 09:44 PM 0
Share

That's not necessary at all ;)

I'll update my answer.

avatar image Simon-O · Sep 24, 2015 at 08:24 PM 1
Share

How about just using conditional compilation? $$anonymous$$uch cleaner, and considerably cheaper than reflection...

 #if UNITY_EDITOR
      Editor.IsPlaying = ....
 #endif

avatar image ChrisBoothman · Mar 20, 2016 at 05:37 PM 0
Share

This worked perfectly for me ... many thanks ... if I could package up all the saved clicks and mouse moves and convert them into bitcoins for you, I would! ;)

avatar image
1

Answer by FiveFingers · May 18, 2013 at 06:01 PM

Application.isPlaying is read only play state. Accessing the menu works, but only on a editor script. Not on a runtime one. EditorApplicatio can't be used there.

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
  • 1
  • 2
  • ›

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

18 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

Related Questions

Initialising List array for use in a custom Editor 1 Answer

Access Monobehavior Instance from Static Function of Editor Script 1 Answer

Is it possible to have editor-only native plugins? 0 Answers

Size of the header of the EditorWindow 1 Answer

Stop a MonoBehavior from being addable as a script? 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