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 thrmotta · Aug 17, 2015 at 04:54 PM · c#scenesavesave scene

How to Intercept Unity "Save Scene As.." right after saving?

Hello, everyone!

So, I have a problem where my application needs to get the name of a saved scene right after pressing the "Save Scene as.." button. How can this be achieved?

I tried using AssetModificationProcessor with OnWillSaveAssets, but this gives me the exact moment BEFORE finishing saving and I need the exact moment AFTER save is finished.

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

Answer by thrmotta · Aug 17, 2015 at 07:17 PM

Answering my own question, I had to create a Singleton and fill the FileSystemWatcher delegates:

 [ExecuteInEditMode]
 class SceneNameSingleton : MonoBehaviour
 {
     private FileSystemWatcher m_SceneFileWatcher;    // This watches to see if we have saved the level
 
     private static SceneNameSingleton instance;
 
     static GameObject genericSingletonGO;
     public static string SINGLETON_NAME = "Singleton";
 
     public static SceneNameSingleton Instance
     {
         get
         {
             if( instance == null )
             {
                 if( genericSingletonGO == null )
                 {
                     genericSingletonGO = GameObject.Find( SINGLETON_NAME );
                     if( genericSingletonGO == null )
                         genericSingletonGO = new GameObject( SINGLETON_NAME );
 
                     
                 }
 
                 if( genericSingletonGO != null && genericSingletonGO.GetComponent<SceneNameSingleton>( ) != null )
                 {
                     instance = genericSingletonGO.GetComponent<SceneNameSingleton>( );
                 }
                 else
                 {  
                     instance = genericSingletonGO.AddComponent<SceneNameSingleton>( );
                 }
             }
             return instance;
         }
     }
 
     void OnSceneFileWatcher_Created( object sender, FileSystemEventArgs e )
     {
         if( e.FullPath.Contains( ".meta" ) ) return;
         if( !e.FullPath.Contains( ".unity" ) ) return;
 
         Debug.Log( "OnSceneFileWatcher_Changed" );
         string sceneName = System.IO.Path.GetFileNameWithoutExtension( e.FullPath );
         Debug.Log( "File: " + sceneName + " " + e.ChangeType );
     }
 
     void OnEnable( )
     {
         Debug.Log( "OnEnable" );
         m_SceneFileWatcher = new FileSystemWatcher( Path.GetFullPath( "Assets" ), "*.unity" );
         m_SceneFileWatcher.Filter = "*.*";
         m_SceneFileWatcher.NotifyFilter = NotifyFilters.LastWrite;
         m_SceneFileWatcher.EnableRaisingEvents = true;
 
         m_SceneFileWatcher.Created += new FileSystemEventHandler( OnSceneFileWatcher_Created );
         m_SceneFileWatcher.Changed+= new FileSystemEventHandler( OnSceneFileWatcher_Created );
     }
 }
 

This way everytime a unity scene is created or modified it'll be detected and logged.

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

26 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How do I create a save scene feature though int value in c# 2 Answers

save scene and load using binary file 1 Answer

how to save the progress on scene1 when it goes to scene2, so when it goes back to scene1 its still the same saved scene 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