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 Firedan1176 · Feb 12, 2015 at 02:34 AM · editorapplication

Unity Editor: Detect Crash OR Editor Exit?

I know Application.Quit is when the built game is exited, but how would I go about doing this for when the editor is exited? A better option would also be a way to detect if there was a crash previously.

Is it possible?

(Detect editor exit so I can create a log, which won't work if it crashes..)

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
0
Best Answer

Answer by incorrect · Feb 12, 2015 at 03:30 AM

I've found one way. :)

You can use ExecuteInEditMode attribute to make it, have an instance of a logger in a scene and make it work like this:

 using UnityEngine;
 using System.Collections;
 using System;
 using System.IO;
 
 [ExecuteInEditMode]
 public class TestScript : MonoBehaviour {
 
     // Use this for initialization
     void Awake () {
         Debug.Log ("It works!");
     }
 
     void OnDestroy()
     {
         string path = @"C:\Users\**YOUR_PROFILE**\Documents\MyTest.txt";
         // This text is added only once to the file. 
         if (File.Exists(path)) 
         {
             // Create a file to write to. 
             using (StreamWriter sw = File.CreateText(path)) 
             {
                 sw.WriteLine(System.DateTime.Now.ToString());
             }    
         }
     }
 }

This code will write closing time to the MyTest.txt using File.AppendText Method, but you can make anything you want inside OnDestroy(), which will appear every time you close the scene with a logger.

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 incorrect · Feb 12, 2015 at 03:33 AM 0
Share

Of course you can write to the file the opening session's id and closing session's id, and if they do not match you will know that last time editor has crashed. It's not hard to make it.

avatar image Firedan1176 · Feb 13, 2015 at 12:31 AM 0
Share

Thank you ! Both answers were helpful.

avatar image
0

Answer by farrisarts · Feb 12, 2015 at 03:04 AM

Normally you would use try/catch and exeptions however since you are talking about the Editor there is no way to detect a crash. In fact, a crash inherently is handled by the operating system. The only ones that can detect any kind of crash is Unity themselves in their engine code.

So in order to get something like this you can actually do a few things to detect when a crash happens and what you were doing before the crash. The easiest way to do this is to write to a log file stream in which you can open up and read after the crash.

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

21 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

Related Questions

OnApplicationExit: System.AppDomain.CurrentDomain.ProcessExit? 0 Answers

Application not installed on android 0 Answers

Is there a way to detect "On Component Attach" and "On Component Remove"?? 2 Answers

On Editor Exit? 0 Answers

Loading a scene from an external source 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