• 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 Duskp · Feb 20, 2013 at 04:54 AM · editorprefabsavegenerated

How to save generated objects?

I have a script that generates a level based on text information, using "room" prefabs I already have saved. That script, however, generates only empty stages I'd like to fill with objects later, on the editor. Is there any way I can save this code-generated object and open it on the editor later? Basically I'm just trying to speed up the level-building process...

Comment
Add comment · Show 2
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 Benproductions1 · Feb 20, 2013 at 05:00 AM 0
Share

alucardj please make your comment an answer, it's really not a comment :)

avatar image AlucardJay · Feb 20, 2013 at 05:19 AM 0
Share

Done, thanks.

2 Replies

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

Answer by AlucardJay · Feb 20, 2013 at 04:54 AM

Information can be saved to PlayerPrefs, a text file or even an image. I think what you want is to execute code for building the skeleton of your scene, then saving that scene so it can be expanded on. Are you familiar with ContextMenu ? This way you can execute code without running the scene, then save the scene with all the modified data.

http://docs.unity3d.com/Documentation/ScriptReference/ContextMenu.html

For example, I wrote a script to find all my waypoints and re-parent them to another object. Just yesterday I had a terrain with no tree colliders, so I wrote a ContextMenu function to find all the trees, and place colliders for me! Run once, scene saved, trees now have colliders.

Here is an example script. Create a new scene, attach this script to an empty gameObject :

 #pragma strict
 
 #if UNITY_EDITOR
 @ContextMenu( "Run From Context Menu" )
 function RunFromContextMenu() 
 {
     Debug.Log("Running from ContextMenu");
     CreateCube();
 }
 #endif
 
 public var cubePosition : Vector3 = Vector3.zero;
 
 function CreateCube() 
 {
     var go : GameObject = GameObject.CreatePrimitive( PrimitiveType.Cube );
     go.transform.position = cubePosition;
 }

Now look in the Inspector, right-click on the script where it says Scriptname (Script) : http://docs.unity3d.com/Documentation/Images/manual/Inspector-3.jpg

In the drop-down menu there should be Run From Context Menu , click on that. Now change the Vector cubePosition and use the context menu again !

Some things may take a while to compute, and yield does not work in edit mode, those are some main considerations. But again with the tree example, 6000 trees took 3 mins and it looked like unity froze, but it is thinking (executing all the code within a single loop), just leave it and wait for all the code to take effect. I mention this because you could be instantiating a large amount of objects, so just be patient =]

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 Duskp · Feb 20, 2013 at 08:59 PM 0
Share

That's exactly what I needed. Thanks!

avatar image
0

Answer by Schnodahipfe · Apr 15, 2013 at 12:21 PM

I had a similar problem and finally found this great project: http://whydoidoit.com/unityserializer/

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

How to modify prefab permanently via script. 0 Answers

Verify Saving Assets key 1 Answer

Need to make a reference in a prefab to itself not to the created instance 2 Answers

Best method to save states in/for a prefab 0 Answers

Created Prefabs and added them into a List in Editor Mode, after PlayMode, these GameObject are not in the List anymore 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