Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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
2
Question by Nick4 · Jun 15, 2014 at 07:14 PM · play-mode

How can I keep the game objects when I quit play mode?

Let's say I generated a few objects during runtime. Is there a way to prevent them being destroyed when I quit play mode and go back to edit mode?

Comment
Add comment · Show 3
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 xandermacleod · Jun 15, 2014 at 07:56 PM 1
Share

it's not exactly what your after but there's an extremely handy plugin on the asset store called Play$$anonymous$$odePersist. It allows you to save out changes you made to components during play mode, so that they remain the same when you exit play mode. I don't know specifically what you want to do, but you could 'mock record' the values you need this way. Not ideal though...

avatar image PouletFrit · Jun 16, 2014 at 03:26 AM 2
Share

An easy way to "keep" you gameObject is to copy them... Just select them before quitting play mode, press Ctrl+C, quit play mode then Ctrl+V

avatar image Nick4 · Jun 16, 2014 at 03:04 PM 0
Share

Thanks guys. I wish there were a way to do it programmatically but what are you gonna do? I guess we'll just have to improvise in situations like this.

1 Reply

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

Answer by fafase · Jun 16, 2014 at 03:25 PM

Here is a quick solution. Store the object with information you need on a file, just a basic text file or xml or json, whatever you want.

Then two ways, either update the file when you create a new object

In case 1, you could create a wrapper to the Instantiate method:

 public static class Utility{
    public static void Instantiate(GameObject prefab, Vector3 position, Quaternion rotation){
        GameObject obj = (GameObject) Object.Instantiate(prefab,position, rotation);
        // Here you add all the file access, writing and closing
       }
    }
 }

or collect all objects in OnApplicationQuit which is called when you stop the play mode.

 void OnApplicationQuit(){
     GameObject[] allObjects = (GameObject[])FindObjectsOfTypeAll(typeof(GameObject));
     foreach(object thisObject in allObjects){
          // Access file, write and close
     }
 }

Then check this video http://unity3d.com/learn/tutorials/modules/intermediate/editor/adding-buttons-to-inspector

and create a button that does the revert effect, that is read the file and create the object stored on it.

 [CustomEditor(typeof(ObjectBuilderScript))]
 public class ObjectBuilderEditor : Editor
 {
     public override void OnInspectorGUI()
     {
         DrawDefaultInspector();
         
         ObjectBuilderScript myScript = (ObjectBuilderScript)target;
         if(GUILayout.Button("Create objects"))
         {
             // Access file, read and create all objects
         }
     }
 }

You are now with your scene in edit mode as it was in play mode.

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 Nick4 · Jun 16, 2014 at 04:27 PM 0
Share

+1, Simple and efficient considering you also took time for CustomEditor.

avatar image Aeyos · Jul 05, 2017 at 01:52 PM 0
Share

Great answer, I was wondering if Editor had something like this already, but it sounds messy and confusing. This solution might just be what I need, thanks!

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

23 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Objects in Play mode to Scene View 1 Answer

How to import the object from server to unity 2 Answers

Material doesn't have a color property '_Color' 4 Answers

Setting Scroll View Width GUILayout 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